-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ING-963: Added a /v1/callerIdentity endpoint.
- Loading branch information
Brett Lawson
committed
Nov 1, 2024
1 parent
d06977e
commit 227c8c5
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,20 @@ | ||
package server_v1 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/couchbase/stellar-gateway/dataapiv1" | ||
) | ||
|
||
func (s *DataApiServer) GetCallerIdentity( | ||
ctx context.Context, in dataapiv1.GetCallerIdentityRequestObject, | ||
) (dataapiv1.GetCallerIdentityResponseObject, error) { | ||
user, _, errSt := s.authHandler.GetOboUserFromRequest(ctx, in.Params.Authorization) | ||
if errSt != nil { | ||
return nil, errSt.Err() | ||
} | ||
|
||
return dataapiv1.GetCallerIdentity200JSONResponse{ | ||
User: &user, | ||
}, nil | ||
} |
This file contains 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,35 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func (s *GatewayOpsTestSuite) TestDapiCallerIdentity() { | ||
s.Run("Basic", func() { | ||
resp := s.sendTestHttpRequest(&testHttpRequest{ | ||
Method: http.MethodGet, | ||
Path: "/v1/callerIdentity", | ||
Headers: map[string]string{ | ||
"Authorization": s.basicRestCreds, | ||
}, | ||
}) | ||
requireRestSuccess(s.T(), resp) | ||
assert.JSONEq(s.T(), fmt.Sprintf(`{"user":"%s"}`, s.testClusterInfo.BasicUser), string(resp.Body)) | ||
}) | ||
|
||
s.Run("InvalidAuth", func() { | ||
resp := s.sendTestHttpRequest(&testHttpRequest{ | ||
Method: http.MethodGet, | ||
Path: "/v1/callerIdentity", | ||
Headers: map[string]string{ | ||
"Authorization": s.badRestCreds, | ||
}, | ||
}) | ||
requireRestError(s.T(), resp, http.StatusForbidden, &testRestError{ | ||
Code: "InvalidAuth", | ||
}) | ||
}) | ||
} |
File renamed without changes.