@@ -15,26 +15,34 @@ func TestCreateUserSelfRegistration(t *testing.T) {
1515 teardown := setup (t )
1616 defer teardown ()
1717
18+ newUserUUID := "867128a6-0e02-431c-ba1e-9e764436dae4"
19+ loginID := "loafoe"
20+ email := "foo@bar.com"
21+ firstName := "La"
22+ lastName := "Foe"
23+
1824 muxIDM .HandleFunc ("/authorize/identity/User" , func (w http.ResponseWriter , r * http.Request ) {
19- if r .Method != "POST" {
20- t .Errorf ("Expected ‘POST’ request, got ‘%s’" , r .Method )
21- }
2225 if auth := r .Header .Get ("Authorization" ); auth != "" {
2326 t .Errorf ("No Authorization header expected, Got: %s" , auth )
27+ w .WriteHeader (http .StatusUnauthorized )
28+ return
2429 }
25- body , _ := ioutil .ReadAll (r .Body )
26- j , _ := gabs .ParseJSON (body )
27- ageValidated , ok := j .Path ("isAgeValidated" ).Data ().(string )
28- if ! ok {
29- t .Errorf ("Missing isAgeValidated field" )
30- }
31- if ageValidated != "true" {
32- t .Errorf ("ageValidated should be true" )
33- }
34-
35- w .Header ().Set ("Content-Type" , "application/json;charset=UTF-8" )
36- w .WriteHeader (http .StatusCreated )
37- _ , _ = io .WriteString (w , `{
30+ switch r .Method {
31+ case "POST" :
32+ body , _ := ioutil .ReadAll (r .Body )
33+ j , _ := gabs .ParseJSON (body )
34+ ageValidated , ok := j .Path ("isAgeValidated" ).Data ().(string )
35+ if ! ok {
36+ t .Errorf ("Missing isAgeValidated field" )
37+ }
38+ if ageValidated != "true" {
39+ t .Errorf ("ageValidated should be true" )
40+ }
41+
42+ w .Header ().Set ("Content-Type" , "application/json;charset=UTF-8" )
43+ w .Header ().Set ("Location" , "/authorize/identity/User/" + newUserUUID )
44+ w .WriteHeader (http .StatusCreated )
45+ _ , _ = io .WriteString (w , `{
3846 "resourceType": "OperationOutcome",
3947 "issue": [
4048 {
@@ -46,13 +54,72 @@ func TestCreateUserSelfRegistration(t *testing.T) {
4654 }
4755 ]
4856 }` )
57+ case "GET" :
58+ w .WriteHeader (http .StatusOK )
59+ _ , _ = io .WriteString (w , `{
60+ "total": 1,
61+ "entry": [
62+ {
63+ "preferredLanguage": "en-US",
64+ "loginId": "` + loginID + `",
65+ "emailAddress": "` + email + `",
66+ "id": "` + newUserUUID + `",
67+ "managingOrganization": "c29cdb88-7cda-4fc1-af8b-ee5947659958",
68+ "name": {
69+ "given": "` + firstName + `",
70+ "family": "` + lastName + `"
71+ },
72+ "memberships": [
73+ {
74+ "organizationId": "c29cdb88-7cda-4fc1-af8b-ee5947659958",
75+ "organizationName": "Pawnee",
76+ "roles": [
77+ "ANALYZE",
78+ "S3CREDSADMINROLE",
79+ "ADMIN"
80+ ],
81+ "groups": [
82+ "S3CredsAdminGroup",
83+ "AdminGroup"
84+ ]
85+ },
86+ {
87+ "organizationId": "d4be75cc-e81b-4d7d-b034-baf6f3f10792",
88+ "organizationName": "Eagleton",
89+ "roles": [
90+ "LOGUSER"
91+ ],
92+ "groups": [
93+ "LogUserGroup"
94+ ]
95+ }
96+ ],
97+ "passwordStatus": {
98+ "passwordExpiresOn": "2022-02-04T10:07:55Z",
99+ "passwordChangedOn": "2020-02-15T10:07:55Z"
100+ },
101+ "accountStatus": {
102+ "mfaStatus": "NOTREQUIRED",
103+ "lastLoginTime": "2020-05-09T12:27:41Z",
104+ "emailVerified": true,
105+ "numberOfInvalidAttempt": 0,
106+ "disabled": false
107+ },
108+ "consentedApps": [
109+ "default default default"
110+ ]
111+ }
112+ ]
113+ }` )
114+ }
115+
49116 })
50117 person := Person {
51118 ResourceType : "Person" ,
52- LoginID : "loafoe" ,
119+ LoginID : loginID ,
53120 Name : Name {
54- Family : "Foe" ,
55- Given : "La" ,
121+ Family : lastName ,
122+ Given : firstName ,
56123 },
57124 Telecom : []TelecomEntry {
58125 {
@@ -66,13 +133,17 @@ func TestCreateUserSelfRegistration(t *testing.T) {
66133 },
67134 IsAgeValidated : "true" ,
68135 }
69- ok , resp , err := client .Users .CreateUser (person )
136+ user , resp , err := client .Users .CreateUser (person )
70137 if ! assert .NotNil (t , resp ) {
71138 return
72139 }
140+ assert .Equal (t , http .StatusOK , resp .StatusCode )
73141 assert .Nil (t , err )
74- assert .True (t , ok )
75- assert .Equal (t , http .StatusCreated , resp .StatusCode )
142+ if ! assert .NotNil (t , user ) {
143+ return
144+ }
145+ assert .Equal (t , newUserUUID , user .ID )
146+ assert .Equal (t , loginID , user .LoginID )
76147}
77148
78149func TestDeleteUser (t * testing.T ) {
0 commit comments