Skip to content

Commit

Permalink
Add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dehort committed Jan 26, 2024
1 parent cd0c4b5 commit 7986055
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions middleware/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func EnforceUserIdentity(next http.Handler) http.Handler {
return
}

// The security model is currently based on the username...so verify we are getting a valid username
if len(username) == 0 {
BadRequestError(w, "Invalid identity header. Missing username data.")
return
}

user := User{
AccountID: id.Identity.AccountNumber,
OrganizationID: id.Identity.OrgID,
Expand Down
12 changes: 12 additions & 0 deletions middleware/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ var _ = Describe("Handler", func() {
`{ "identity": {"account_number": "540155", "auth_type": "jwt-auth", "org_id": "1979710", "internal": {"org_id": "1979710"}, "type": "User", "user": {"username": "username", "email": "[email protected]", "first_name": "Jake", "last_name": "Logan", "is_active": true, "is_org_admin": false, "is_internal": true, "locale": "North America", "user_id": "1010101"} } }`,
http.StatusOK,
),
Entry("Test with valid service account", "540155", "1979710", "service-account-username",
`{ "identity": {"account_number": "540155", "auth_type": "jwt-auth", "org_id": "1979710", "internal": {"org_id": "1979710"}, "type": "ServiceAccount", "service_account": { "client_id": "b69eaf9e-e6a6-4f9e-805e-02987daddfbd", "username": "service-account-username" } } }`,
http.StatusOK,
),
Entry("Test with empty service account (handle the null)", "540155", "1979710", "service-account-username",
`{ "identity": {"account_number": "540155", "auth_type": "jwt-auth", "org_id": "1979710", "internal": {"org_id": "1979710"}, "type": "ServiceAccount", "service_account": } }`,
http.StatusBadRequest,
),
Entry("Test with service account with empty username", "540155", "1979710", "service-account-username",
`{ "identity": {"account_number": "540155", "auth_type": "jwt-auth", "org_id": "1979710", "internal": {"org_id": "1979710"}, "type": "ServiceAccount", "service_account": { "client_id": "b69eaf9e-e6a6-4f9e-805e-02987daddfbd", "username": null } } }`,
http.StatusBadRequest,
),
Entry("Test without org_id", "540155", "", "username",
`{ "identity": {"account_number": "540155", "auth_type": "jwt-auth", "internal": {}, "type": "User", "user": {"username": "username", "email": "[email protected]", "first_name": "Jake", "last_name": "Logan", "is_active": true, "is_org_admin": false, "is_internal": true, "locale": "North America", "user_id": "1010101"} } }`,
http.StatusBadRequest,
Expand Down

0 comments on commit 7986055

Please sign in to comment.