Skip to content
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

Add support for using username in get account #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions authn/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func (ac *Client) claimsFromVerifier(idToken string, verifier JWTClaimsExtractor
return claims, nil
}

// GetAccount gets the account with the associated id
func (ac *Client) GetAccount(id string) (*Account, error) { // Should this be a string or an int?
return ac.iclient.GetAccount(id)
// GetAccount gets the account with the associated id or username
func (ac *Client) GetAccount(idOrUsername string) (*Account, error) {
return ac.iclient.GetAccount(idOrUsername)
}

// Update updates the account with the associated id
Expand Down
6 changes: 3 additions & 3 deletions authn/internal_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func (ic *internalClient) Key(kid string) ([]jose.JSONWebKey, error) {
return jwks.Key(kid), nil
}

// GetAccount gets the account details for the specified account id
func (ic *internalClient) GetAccount(id string) (*Account, error) {
resp, err := ic.doWithAuth(get, "accounts/"+id, nil)
// GetAccount gets the account details for the specified account id or username
func (ic *internalClient) GetAccount(idOrUsername string) (*Account, error) {
resp, err := ic.doWithAuth(get, "accounts/"+idOrUsername, nil)
if err != nil {
return nil, err
}
Expand Down
44 changes: 30 additions & 14 deletions authn/internal_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func testingHTTPClient(handler http.Handler) (*http.Client, func()) {
// Based on information at https://keratin.github.io/authn-server/#/api?id=get-account
func TestICGetAccount(t *testing.T) {
type request struct {
url string
htusername string
htpassword string
id string
url string
htusername string
htpassword string
idOrUsername string
}
type response struct {
id int
Expand All @@ -71,10 +71,10 @@ func TestICGetAccount(t *testing.T) {
}{
{
request: request{
url: "http://test.com",
htusername: "username",
htpassword: "password",
id: "1",
url: "http://test.com",
htusername: "username",
htpassword: "password",
idOrUsername: "1",
},
response: response{
id: 1,
Expand All @@ -87,10 +87,26 @@ func TestICGetAccount(t *testing.T) {
},
{
request: request{
url: "http://test.com",
htusername: "username",
htpassword: "password",
id: "1",
url: "http://test.com",
htusername: "username",
htpassword: "password",
idOrUsername: "[email protected]",
},
response: response{
id: 1,
username: "[email protected]",
locked: true,
deleted: true,
code: http.StatusOK,
errorMsg: "",
},
},
{
request: request{
url: "http://test.com",
htusername: "username",
htpassword: "password",
idOrUsername: "1",
},
response: response{
code: http.StatusNotFound,
Expand All @@ -106,7 +122,7 @@ func TestICGetAccount(t *testing.T) {
assert.Equal(t, http.MethodGet, r.Method)
assert.Equal(t, tc.request.htusername, username)
assert.Equal(t, tc.request.htpassword, password)
assert.Equal(t, "/accounts/"+tc.request.id, r.URL.Path)
assert.Equal(t, "/accounts/"+tc.request.idOrUsername, r.URL.Path)
w.WriteHeader(tc.response.code)
//if we're mocking a good request, return the json
if tc.response.code == http.StatusOK {
Expand All @@ -129,7 +145,7 @@ func TestICGetAccount(t *testing.T) {
}
cli.client = httpClient

account, err := cli.GetAccount(tc.request.id)
account, err := cli.GetAccount(tc.request.idOrUsername)
if tc.response.errorMsg == "" { //Expecting no error
assert.Nil(t, err)
assert.Equal(t, tc.response.id, account.ID)
Expand Down