Skip to content

Commit 6486364

Browse files
authored
Remove email validation on UserSpec.Email field to allow free-form (non-email) values for that field (#123)
1 parent 5e6c531 commit 6486364

File tree

2 files changed

+43
-47
lines changed

2 files changed

+43
-47
lines changed

pkg/authz/user/spec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type UserSpec struct {
1111
UserId string `json:"userId" validate:"omitempty,valid_object_id"`
12-
Email *string `json:"email" validate:"omitempty,email"`
12+
Email *string `json:"email"`
1313
CreatedAt time.Time `json:"createdAt"`
1414
}
1515

@@ -29,5 +29,5 @@ func (spec UserSpec) ToObjectSpec() *object.ObjectSpec {
2929
}
3030

3131
type UpdateUserSpec struct {
32-
Email *string `json:"email" validate:"omitempty,email"`
32+
Email *string `json:"email"`
3333
}

tests/users-crud.json

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"statusCode": 200,
1717
"body": {
1818
"userId": "test_-.|@User123",
19-
"email": null,
20-
"createdAt": "2022-09-30T17:04:20Z"
19+
"email": null
2120
}
2221
}
2322
},
@@ -34,8 +33,7 @@
3433
"statusCode": 200,
3534
"body": {
3635
"userId": "4444444444444",
37-
"email": null,
38-
"createdAt": "2022-09-30T17:04:20Z"
36+
"email": null
3937
}
4038
}
4139
},
@@ -53,8 +51,7 @@
5351
"statusCode": 200,
5452
"body": {
5553
"userId": "5555555555555",
56-
"email": "[email protected]",
57-
"createdAt": "2022-09-30T17:04:20Z"
54+
"email": "[email protected]"
5855
}
5956
}
6057
},
@@ -69,8 +66,7 @@
6966
"statusCode": 200,
7067
"body": {
7168
"userId": "{{ createUserWithGeneratedIdNoEmail.userId }}",
72-
"email": null,
73-
"createdAt": "2022-09-30T17:04:20Z"
69+
"email": null
7470
}
7571
}
7672
},
@@ -87,8 +83,24 @@
8783
"statusCode": 200,
8884
"body": {
8985
"userId": "{{ createUserWithGeneratedIdAndEmail.userId }}",
90-
"email": "[email protected]",
91-
"createdAt": "2022-09-30T17:04:20Z"
86+
"email": "[email protected]"
87+
}
88+
}
89+
},
90+
{
91+
"name": "createUserWithNonEmail",
92+
"request": {
93+
"method": "POST",
94+
"url": "/v1/users",
95+
"body": {
96+
"email": "not-an-email"
97+
}
98+
},
99+
"expectedResponse": {
100+
"statusCode": 200,
101+
"body": {
102+
"userId": "{{ createUserWithNonEmail.userId }}",
103+
"email": "not-an-email"
92104
}
93105
}
94106
},
@@ -101,30 +113,29 @@
101113
"expectedResponse": {
102114
"statusCode": 200,
103115
"body": [
116+
{
117+
"userId": "{{ createUserWithNonEmail.userId }}",
118+
"email": "not-an-email"
119+
},
104120
{
105121
"userId": "{{ createUserWithGeneratedIdAndEmail.userId }}",
106-
"email": "[email protected]",
107-
"createdAt": "2022-09-30T17:04:20Z"
122+
"email": "[email protected]"
108123
},
109124
{
110125
"userId": "{{ createUserWithGeneratedIdNoEmail.userId }}",
111-
"email": null,
112-
"createdAt": "2022-09-30T17:04:20Z"
126+
"email": null
113127
},
114128
{
115129
"userId": "5555555555555",
116-
"email": "[email protected]",
117-
"createdAt": "2022-09-30T17:04:20Z"
130+
"email": "[email protected]"
118131
},
119132
{
120133
"userId": "4444444444444",
121-
"email": null,
122-
"createdAt": "2022-09-30T17:04:20Z"
134+
"email": null
123135
},
124136
{
125137
"userId": "test_-.|@User123",
126-
"email": null,
127-
"createdAt": "2022-09-30T17:04:20Z"
138+
"email": null
128139
}
129140
]
130141
}
@@ -139,8 +150,7 @@
139150
"statusCode": 200,
140151
"body": {
141152
"userId": "{{ createUserWithGeneratedIdNoEmail.userId }}",
142-
"email": null,
143-
"createdAt": "2022-09-30T17:04:20Z"
153+
"email": null
144154
}
145155
}
146156
},
@@ -157,8 +167,7 @@
157167
"statusCode": 200,
158168
"body": {
159169
"userId": "{{ createUserWithGeneratedIdNoEmail.userId }}",
160-
"email": "[email protected]",
161-
"createdAt": "2022-09-30T17:04:20Z"
170+
"email": "[email protected]"
162171
}
163172
}
164173
},
@@ -172,8 +181,7 @@
172181
"statusCode": 200,
173182
"body": {
174183
"userId": "{{ createUserWithGeneratedIdNoEmail.userId }}",
175-
"email": "[email protected]",
176-
"createdAt": "2022-09-30T17:04:20Z"
184+
"email": "[email protected]"
177185
}
178186
}
179187
},
@@ -191,8 +199,7 @@
191199
"statusCode": 200,
192200
"body": {
193201
"userId": "{{ createUserWithGeneratedIdNoEmail.userId }}",
194-
"email": "[email protected]",
195-
"createdAt": "2022-09-30T17:04:20Z"
202+
"email": "[email protected]"
196203
}
197204
}
198205
},
@@ -234,22 +241,13 @@
234241
}
235242
},
236243
{
237-
"name": "failToCreateAUserWithInvalidEmail",
244+
"name": "deleteUserWithNonEmail",
238245
"request": {
239-
"method": "POST",
240-
"url": "/v1/users",
241-
"body": {
242-
"userId": "invalid-email",
243-
"email": "invalid-email"
244-
}
246+
"method": "DELETE",
247+
"url": "/v1/users/{{ createUserWithNonEmail.userId }}"
245248
},
246249
"expectedResponse": {
247-
"statusCode": 400,
248-
"body": {
249-
"code": "invalid_parameter",
250-
"message": "must be a valid email",
251-
"parameter": "email"
252-
}
250+
"statusCode": 200
253251
}
254252
},
255253
{
@@ -305,8 +303,7 @@
305303
"statusCode": 200,
306304
"body": {
307305
"userId": "4444444444444",
308-
"email": null,
309-
"createdAt": "2022-09-30T17:04:20Z"
306+
"email": null
310307
}
311308
}
312309
},
@@ -320,8 +317,7 @@
320317
"statusCode": 200,
321318
"body": {
322319
"userId": "4444444444444",
323-
"email": null,
324-
"createdAt": "2022-09-30T17:04:20Z"
320+
"email": null
325321
}
326322
}
327323
},

0 commit comments

Comments
 (0)