-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically share demo account for new users with clinic role
- Loading branch information
Darin Krauss
committed
Apr 20, 2017
1 parent
52c4b8a
commit df9e061
Showing
5 changed files
with
107 additions
and
4 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
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ var ( | |
LongTermKey: "thelongtermkey", | ||
Salt: "a mineral substance composed primarily of sodium chloride", | ||
VerificationSecret: "", | ||
ClinicDemoUserID: "00000000", | ||
} | ||
/* | ||
* users and tokens | ||
|
@@ -435,6 +436,17 @@ func Test_CreateUser_Error_ErrorUpsertingUser(t *testing.T) { | |
T_ExpectErrorResponse(t, response, 500, "Error creating the user") | ||
} | ||
|
||
func Test_CreateUser_Error_ErrorSettingPermissions(t *testing.T) { | ||
responsableStore.FindUsersResponses = []FindUsersResponse{{[]*User{}, nil}} | ||
responsableStore.UpsertUserResponses = []error{nil} | ||
responsableGatekeeper.SetPermissionsResponses = []PermissionsResponse{{clients.Permissions{}, errors.New("ERROR")}} | ||
defer T_ExpectResponsablesEmpty(t) | ||
|
||
body := "{\"username\": \"[email protected]\", \"emails\": [\"[email protected]\"], \"password\": \"12345678\", \"roles\": [\"clinic\"]}" | ||
response := T_PerformRequestBody(t, "POST", "/user", body) | ||
T_ExpectErrorResponse(t, response, 500, "Error creating the user") | ||
} | ||
|
||
func Test_CreateUser_Error_ErrorAddingToken(t *testing.T) { | ||
responsableStore.FindUsersResponses = []FindUsersResponse{{[]*User{}, nil}} | ||
responsableStore.UpsertUserResponses = []error{nil} | ||
|
@@ -449,14 +461,15 @@ func Test_CreateUser_Error_ErrorAddingToken(t *testing.T) { | |
func Test_CreateUser_Success(t *testing.T) { | ||
responsableStore.FindUsersResponses = []FindUsersResponse{{[]*User{}, nil}} | ||
responsableStore.UpsertUserResponses = []error{nil} | ||
responsableGatekeeper.SetPermissionsResponses = []PermissionsResponse{{clients.Permissions{}, nil}} | ||
responsableStore.AddTokenResponses = []error{nil} | ||
defer T_ExpectResponsablesEmpty(t) | ||
|
||
body := "{\"username\": \"[email protected]\", \"emails\": [\"[email protected]\"], \"password\": \"12345678\"}" | ||
body := "{\"username\": \"[email protected]\", \"emails\": [\"[email protected]\"], \"password\": \"12345678\", \"roles\": [\"clinic\"]}" | ||
response := T_PerformRequestBody(t, "POST", "/user", body) | ||
successResponse := T_ExpectSuccessResponseWithJSONMap(t, response, 201) | ||
T_ExpectElementMatch(t, successResponse, "userid", `\A[0-9a-f]{10}\z`, true) | ||
T_ExpectEqualsMap(t, successResponse, map[string]interface{}{"emailVerified": false, "emails": []interface{}{"[email protected]"}, "username": "[email protected]"}) | ||
T_ExpectEqualsMap(t, successResponse, map[string]interface{}{"emailVerified": false, "emails": []interface{}{"[email protected]"}, "username": "[email protected]", "roles": []interface{}{"clinic"}}) | ||
if response.Header().Get(TP_SESSION_TOKEN) == "" { | ||
t.Fatalf("Missing expected %s header", TP_SESSION_TOKEN) | ||
} | ||
|
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 |
---|---|---|
|
@@ -414,6 +414,72 @@ func Test_NewUserDetails_Validate_Valid(t *testing.T) { | |
} | ||
} | ||
|
||
func Test_NewUserDetails_HasRole_Multiple(t *testing.T) { | ||
username := "[email protected]" | ||
password := "12345678" | ||
details := &NewUserDetails{Username: &username, Emails: []string{"[email protected]", "[email protected]"}, Password: &password, Roles: []string{"clinic", "other"}} | ||
if !details.HasRole("clinic") { | ||
t.Fatalf("HasRole returned false when should have returned true") | ||
} | ||
if details.HasRole("missing") { | ||
t.Fatalf("HasRole returned true when should have returned false") | ||
} | ||
} | ||
|
||
func Test_NewUserDetails_HasRole_One(t *testing.T) { | ||
username := "[email protected]" | ||
password := "12345678" | ||
details := &NewUserDetails{Username: &username, Emails: []string{"[email protected]", "[email protected]"}, Password: &password, Roles: []string{"clinic"}} | ||
if !details.HasRole("clinic") { | ||
t.Fatalf("HasRole returned false when should have returned true") | ||
} | ||
if details.HasRole("missing") { | ||
t.Fatalf("HasRole returned true when should have returned false") | ||
} | ||
} | ||
|
||
func Test_NewUserDetails_HasRole_Empty(t *testing.T) { | ||
username := "[email protected]" | ||
password := "12345678" | ||
details := &NewUserDetails{Username: &username, Emails: []string{"[email protected]", "[email protected]"}, Password: &password, Roles: []string{}} | ||
if details.HasRole("clinic") { | ||
t.Fatalf("HasRole returned true when should have returned false") | ||
} | ||
if details.HasRole("missing") { | ||
t.Fatalf("HasRole returned true when should have returned false") | ||
} | ||
} | ||
|
||
func Test_NewUserDetails_HasRole_Missing(t *testing.T) { | ||
username := "[email protected]" | ||
password := "12345678" | ||
details := &NewUserDetails{Username: &username, Emails: []string{"[email protected]", "[email protected]"}, Password: &password} | ||
if details.HasRole("clinic") { | ||
t.Fatalf("HasRole returned true when should have returned false") | ||
} | ||
if details.HasRole("missing") { | ||
t.Fatalf("HasRole returned true when should have returned false") | ||
} | ||
} | ||
|
||
func Test_NewUserDetails_IsClinic_Valid(t *testing.T) { | ||
username := "[email protected]" | ||
password := "12345678" | ||
details := &NewUserDetails{Username: &username, Emails: []string{"[email protected]", "[email protected]"}, Password: &password, Roles: []string{"clinic"}} | ||
if !details.IsClinic() { | ||
t.Fatalf("IsClinic returned false when should have returned true") | ||
} | ||
} | ||
|
||
func Test_NewUserDetails_IsClinic_Invalid(t *testing.T) { | ||
username := "[email protected]" | ||
password := "12345678" | ||
details := &NewUserDetails{Username: &username, Emails: []string{"[email protected]", "[email protected]"}, Password: &password} | ||
if details.IsClinic() { | ||
t.Fatalf("IsClinic returned true when should have returned false") | ||
} | ||
} | ||
|
||
func Test_ParseNewUserDetails_InvalidJSON(t *testing.T) { | ||
source := "" | ||
details, err := ParseNewUserDetails(strings.NewReader(source)) | ||
|