Skip to content

Fix duplicate GitHub signup, improve S3 error msgs - #176

Merged
neuromechanist merged 3 commits into
devfrom
175-s3-access-issue
Feb 24, 2026
Merged

neuromechanist merged 3 commits into
devfrom
175-s3-access-issue

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

  • Add GitHub username duplicate check to signup endpoint (was only checking username and email)
  • Add DB UNIQUE constraint on github_username via migration 0012
  • Improve S3 credential decryption error messages with actionable guidance for environment mismatch issues
  • Handle DB UNIQUE constraint violations as safety net in signup catch block (returns 409 instead of 500)
  • Update check-github endpoint to also report if a GitHub username is already registered

Root Cause (S3 Issue)

Arno's account was approved via the dev worker, which encrypted his S3 credentials with the dev ENCRYPTION_KEY. When he hit the production API for upload, decryption failed due to key mismatch. Fix: regenerated credentials on production + improved error messaging for future diagnosis.

Test plan

  • New test: signup with existing github_username returns 409
  • All 54 API tests pass
  • Migration applied to remote D1
  • Deployed to both dev and production
  • Arno's S3 credentials regenerated on production

Fixes #175

Sync dev to main: v0.6.1 fixes and docs update
- Add GitHub username duplicate check to signup endpoint
- Add UNIQUE constraint on github_username (migration 0012)
- Improve S3 credential decryption error messages with
  actionable guidance for environment mismatch issues
- Handle DB UNIQUE constraint errors as safety net in
  signup catch block (returns 409 instead of 500)
- Update check-github endpoint to report if username is
  already registered in NEMAR
- Add test for duplicate github_username signup

Fixes #175
- Use COLLATE NOCASE for github_username UNIQUE index and
  queries (GitHub usernames are case-insensitive)
- Store canonical GitHub login from API, not user input
- Separate GitHub API and DB error handling in check-github
- Skip DB query in check-github when GitHub user not found
- Log unhandled column in UNIQUE constraint fallback
- Standardize S3 error message text across both endpoints
- Add tests for check-github endpoint (registered field,
  unregistered user, missing param)
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review Findings and Fixes

Ran comprehensive PR review (code-reviewer, silent-failure-hunter, pr-test-analyzer, code-simplifier). All actionable issues addressed in commit 7833aa9.

Issue Severity Fix
Case-insensitive GitHub usernames High COLLATE NOCASE on UNIQUE index + all queries; store canonical githubUser.login from API
DB error mislabeled in check-github High Separated GitHub API and DB try/catch blocks
Skip unnecessary DB query Recommended Only query DB when GitHub user exists
Generic UNIQUE fallback logging Medium Added console.error for unhandled column
S3 error message inconsistency Medium Standardized to "Failed to access S3 credentials"
No tests for check-github endpoint Important Added 3 tests: registered, unregistered, missing param

All 57 tests pass. Both prod and dev deployed. Migration updated on remote D1.

@neuromechanist
neuromechanist merged commit 16f9e5c into dev Feb 24, 2026
7 checks passed
@neuromechanist
neuromechanist deleted the 175-s3-access-issue branch February 24, 2026 06:26
neuromechanist added a commit that referenced this pull request May 11, 2026
#430 CI api-test failure root cause: validateGitHubUsername() ran
before the dup check, so a signup attempt with an already-registered
github_username that happens not to resolve on GitHub (renamed/deleted
account, or test seed with a fake username) returned 400 instead of 409.

Now we direct-check the raw input first (case-insensitive). The GitHub
API call is retained for canonical-login dedup but only re-checks when
GitHub normalized the case (the original motivation in #176 for doing
validation first). Saves one REST call on the common already-registered
case and unblocks api-test.

Test "signup with existing github_username returns 409" in
test/api.test.ts:124 is the assertion.
neuromechanist added a commit that referenced this pull request May 11, 2026
* fix: three publication regressions (#429)

1. backend/src/services/github.ts: pin archiver to ^7.0.1 in the
   Generate Archive workflow template. archiver 8.x is ESM-only and
   require("archiver") no longer returns the factory function, causing
   "archiver is not a function" on every newly published dataset.

2. backend/src/routes/admin.ts: skip the createOrUpdateFile call in
   update_readme when the DOI badge is already present and the README
   does not need renaming. Previously the orchestrator shipped an
   empty "Add DOI badge: ..." commit on every --resume, which retriggered
   BIDS Validation each time.

3. src/lib/import-openneuro.ts: restore skipCiCheck=true (4th arg of
   approvePublication) in the import retry loop. PR #271 had flipped it
   to false on the assumption that the BIDS check could complete in time,
   but in practice the push + approve race always loses and imports
   wind up in 'bids_validation_pending'. OpenNeuro datasets are
   validated upstream and the CI runs separately after push regardless.

* fix: address PR review findings on #430

- backend/src/services/doi.ts: extract planReadmeBadgeCommit() pure helper.
  Tightens the skip path to require that the existing badge encode the
  *current* concept DOI; without that check a stale badge (from re-registered
  or provider-migrated DOIs) would be silently kept. Detects mismatch and
  emits a "Replace stale DOI badge" commit. URL-encoded DOI form is
  recognized as a match (matches the actual badge URL encoding).
- backend/src/routes/admin.ts: use planReadmeBadgeCommit() in update_readme.
- test/readme-badge-plan.test.ts: unit tests covering skip, stale-badge
  rewrite, no-README, rename-needed, and encoded-DOI cases (6 cases).
- test/workflow-yaml.test.ts: assert generate-archive.yml pins
  archiver@^7 to catch a future unpinned regression.
- Trim verbose comments in github.ts and import-openneuro.ts per review.

Follow-up #431 tracks the design improvement of replacing
skipCiCheck=true with a bounded poll on workflow_runs.

* fix(auth): direct github_username dup check before GitHub validation

#430 CI api-test failure root cause: validateGitHubUsername() ran
before the dup check, so a signup attempt with an already-registered
github_username that happens not to resolve on GitHub (renamed/deleted
account, or test seed with a fake username) returned 400 instead of 409.

Now we direct-check the raw input first (case-insensitive). The GitHub
API call is retained for canonical-login dedup but only re-checks when
GitHub normalized the case (the original motivation in #176 for doing
validation first). Saves one REST call on the common already-registered
case and unblocks api-test.

Test "signup with existing github_username returns 409" in
test/api.test.ts:124 is the assertion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant