Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func TestWorkspaceAuth_ValidOrgToken_SetsOrgIDContext(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-org-abc", "tok_test", "00000000-0000-0000-0000-000000000001"))

// Best-effort last_used_at update after Validate succeeds.
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-org-abc").
WillReturnResult(sqlmock.NewResult(0, 1))

r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
v, exists := c.Get("org_id")
Expand Down Expand Up @@ -84,6 +89,11 @@ func TestWorkspaceAuth_ValidOrgToken_OrgIDNULL_DoesNotSetContext(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-old-xyz", "tok_old_", nil))

// Best-effort last_used_at update after Validate succeeds (even for NULL org_id).
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-old-xyz").
WillReturnResult(sqlmock.NewResult(0, 1))

r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
_, exists := c.Get("org_id")
Expand Down Expand Up @@ -216,6 +226,11 @@ func TestWorkspaceAuth_OrgToken_DBRowScanError_DoesNotPanic(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-ok", "tok_tok_", "00000000-0000-0000-0000-000000000099"))

// Best-effort last_used_at update after Validate succeeds.
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-ok").
WillReturnResult(sqlmock.NewResult(0, 1))

r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
// org_id key may or may not be set — either is acceptable here.
Expand Down Expand Up @@ -255,6 +270,11 @@ func TestWorkspaceAuth_OrgToken_SetsAllContextKeys(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).
AddRow("tok-full", "tok_fu_", expectedOrgID))

// Best-effort last_used_at update after Validate succeeds.
mock.ExpectExec("UPDATE org_api_tokens SET last_used_at").
WithArgs("tok-full").
WillReturnResult(sqlmock.NewResult(0, 1))

r := gin.New()
r.GET("/workspaces/:id/secrets", WorkspaceAuth(mockDB), func(c *gin.Context) {
id, ok := c.Get("org_token_id")
Expand Down
Loading