-
Notifications
You must be signed in to change notification settings - Fork 609
refactor: /v2/getKey and /v2/whoami #3799
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
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5d15aa1
refactor: get keys into a single query
ogzhanolguncu f38e815
fix: ratelimit response
ogzhanolguncu 6ed860d
refactor: whoami into a single query
ogzhanolguncu 6c4c4ae
refactor: use key data
ogzhanolguncu b30c2f0
fix: condition
ogzhanolguncu f26b9a4
refactor: use keydata
ogzhanolguncu 3058122
test: add more tests
ogzhanolguncu 5fd848a
test: add missing 500 tests
ogzhanolguncu de2780a
fix: test path and add deterministic slugs order
ogzhanolguncu ce1e0c2
fix: bearer check
ogzhanolguncu bdb312d
fix: remove redundant checks
ogzhanolguncu 0dbdb6a
fix: add missing nil checks
ogzhanolguncu 0e340dc
test: add test for key_data
ogzhanolguncu 336bd34
test: add more details happy path for keydata
ogzhanolguncu 84fc72c
Merge branch 'main' of github.com:unkeyed/unkey into refactor-get-key
ogzhanolguncu d2383b7
fix: pr comments
ogzhanolguncu 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package handler_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "github.com/unkeyed/unkey/go/apps/api/openapi" | ||
| handler "github.com/unkeyed/unkey/go/apps/api/routes/v2_keys_get_key" | ||
| "github.com/unkeyed/unkey/go/pkg/ptr" | ||
| "github.com/unkeyed/unkey/go/pkg/testutil" | ||
| "github.com/unkeyed/unkey/go/pkg/uid" | ||
| ) | ||
|
|
||
| func TestInternalError(t *testing.T) { | ||
ogzhanolguncu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| h := testutil.NewHarness(t) | ||
| route := &handler.Handler{ | ||
| Logger: h.Logger, | ||
| DB: h.DB, | ||
| Keys: h.Keys, | ||
| Auditlogs: h.Auditlogs, | ||
| Vault: h.Vault, | ||
| } | ||
| h.Register(route) | ||
| rootKey := h.CreateRootKey(h.Resources().UserWorkspace.ID, "api.*.read_key") | ||
| headers := http.Header{ | ||
| "Content-Type": {"application/json"}, | ||
| "Authorization": {fmt.Sprintf("Bearer %s", rootKey)}, | ||
| } | ||
|
|
||
| t.Run("database connection closed during request", func(t *testing.T) { | ||
| // Close the database connections to simulate a database failure | ||
| err := h.DB.Close() | ||
| require.NoError(t, err) | ||
| req := handler.Request{ | ||
| KeyId: uid.New(uid.KeyPrefix), | ||
| Decrypt: ptr.P(false), | ||
| } | ||
|
|
||
| res := testutil.CallRoute[handler.Request, openapi.InternalServerErrorResponse](h, route, headers, req) | ||
| require.Equal(t, 500, res.Status) | ||
| require.NotNil(t, res.Body) | ||
| require.Contains(t, res.Body.Error.Detail, "We could not load the requested key") | ||
| }) | ||
ogzhanolguncu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
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.