-
Notifications
You must be signed in to change notification settings - Fork 574
Seed the library on a fresh deploy, before any account exists #1221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
| ) | ||
|
|
||
| // The import-library auth gate is security-sensitive: it opens an | ||
| // unauthenticated write path, so its exact conditions are pinned here. The | ||
| // gate must (a) always let authed/localhost callers through, (b) allow an | ||
| // unauthenticated remote caller ONLY on a fresh server — zero sites AND an | ||
| // empty library, so the path is genuinely create-only — and (c) fail closed | ||
| // when a lookup errors. | ||
| func TestLibraryImportAuthDecision(t *testing.T) { | ||
| lookupErr := errors.New("db down") | ||
|
|
||
| cases := []struct { | ||
| name string | ||
| authed bool | ||
| isLocal bool | ||
| siteCount int | ||
| libraryCount int | ||
| lookupErr error | ||
| wantReject string | ||
| wantFresh bool | ||
| }{ | ||
| { | ||
| name: "authed remote passes without lookup", | ||
| authed: true, | ||
| }, | ||
| { | ||
| name: "localhost passes without lookup", | ||
| isLocal: true, | ||
| }, | ||
| { | ||
| name: "authed still passes even with sites and library present", | ||
| authed: true, | ||
| siteCount: 5, | ||
| libraryCount: 12, | ||
| }, | ||
| { | ||
| name: "unauthenticated remote on fully fresh server is allowed and create-only", | ||
| // zero sites, empty library | ||
| wantFresh: true, | ||
| }, | ||
| { | ||
| name: "unauthenticated remote with sites is rejected", | ||
| siteCount: 1, | ||
| wantReject: "unauthorized", | ||
| }, | ||
| { | ||
| name: "unauthenticated remote with an existing library is rejected even at zero sites", | ||
| libraryCount: 1, | ||
| wantReject: "unauthorized", | ||
| }, | ||
| { | ||
| name: "site lookup error fails closed", | ||
| lookupErr: lookupErr, | ||
| wantReject: "internal", | ||
| }, | ||
| { | ||
| name: "lookup error takes precedence over zero counts", | ||
| siteCount: 0, | ||
| libraryCount: 0, | ||
| lookupErr: lookupErr, | ||
| wantReject: "internal", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| got := libraryImportAuthDecision(tc.authed, tc.isLocal, tc.siteCount, tc.libraryCount, tc.lookupErr) | ||
| if got.reject != tc.wantReject { | ||
| t.Errorf("reject = %q, want %q", got.reject, tc.wantReject) | ||
| } | ||
| if got.freshServer != tc.wantFresh { | ||
| t.Errorf("freshServer = %v, want %v", got.freshServer, tc.wantFresh) | ||
| } | ||
| // A rejected request must never be marked fresh (would imply a | ||
| // create-only seed on a denied path). | ||
| if got.reject != "" && got.freshServer { | ||
| t.Errorf("rejected decision marked freshServer") | ||
| } | ||
| // A fresh decision must be strictly create-only: zero sites AND | ||
| // empty library. | ||
| if got.freshServer && (tc.siteCount > 0 || tc.libraryCount > 0) { | ||
| t.Errorf("freshServer granted with siteCount=%d libraryCount=%d", tc.siteCount, tc.libraryCount) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.