@@ -19,8 +19,8 @@ testCases.forEach(function (testCase) {
19
19
describe ( 'authentication-' + testCase , function ( ) {
20
20
21
21
var dbName = testCase === 'normal' ?
22
- 'http://localhost:5984/testdb' :
23
- 'http://localhost:5984/testdb/' ; // trailing slash
22
+ 'http://localhost:5984/testdb' :
23
+ 'http://localhost:5984/testdb/' ; // trailing slash
24
24
25
25
var db ;
26
26
@@ -141,6 +141,73 @@ testCases.forEach(function (testCase) {
141
141
} ) ;
142
142
} ) ;
143
143
144
+ var reservedWords = [
145
+ '_id' ,
146
+ '_rev' ,
147
+ 'name' ,
148
+ 'type' ,
149
+ 'roles' ,
150
+ 'password' ,
151
+ 'password_scheme' ,
152
+ 'iterations' ,
153
+ 'derived_key' ,
154
+ 'salt'
155
+ ] ;
156
+
157
+ reservedWords . forEach ( function ( key ) {
158
+ it ( 'Test changing metadata using reserved word "' + key + '"' , function ( ) {
159
+ return db . signup ( 'robin' , 'dickgrayson' ) . then ( function ( res ) {
160
+ res . ok . should . equal ( true ) ;
161
+ return db . login ( 'robin' , 'dickgrayson' ) ;
162
+ } ) . then ( function ( ) {
163
+ return db . getUser ( 'robin' ) . then ( function ( user ) {
164
+ var metadata = { } ;
165
+ metadata [ key ] = 'test' ;
166
+ return db . putUser ( 'robin' , { metadata : metadata } ) . then ( function ( res ) {
167
+ res . ok . should . not . equal ( true ) ;
168
+ } ) . catch ( function ( err ) {
169
+ should . exist ( err ) ;
170
+ err . status . should . equal ( 400 ) ;
171
+ err . name . should . equal ( 'authentication_error' ) ;
172
+ err . message . should . equal ( 'cannot use reserved word in metadata: "' + key + '"' ) ;
173
+ err . error . should . equal ( true ) ;
174
+
175
+ if ( key === 'password' ) {
176
+ return db . login ( 'robin' , 'dickgrayson' ) . then ( function ( res ) {
177
+ res . ok . should . equal ( true ) ;
178
+ } ) . catch ( function ( err ) {
179
+ should . not . exist ( err ) ;
180
+ } ) ;
181
+ } else {
182
+ return db . getUser ( 'robin' ) . then ( function ( changedUser ) {
183
+ changedUser [ key ] . should . deep . equal ( user [ key ] ) ;
184
+ } ) . catch ( function ( err ) {
185
+ should . not . exist ( err ) ;
186
+ } ) ;
187
+ }
188
+ } ) ;
189
+ } ) ;
190
+ } ) ;
191
+ } ) ;
192
+ } ) ;
193
+
194
+ it ( 'Test changing metadata using non-reserved word "metadata"' , function ( ) {
195
+ var metadata = { test : 'test' } ;
196
+ return db . signup ( 'robin' , 'dickgrayson' ) . then ( function ( res ) {
197
+ res . ok . should . equal ( true ) ;
198
+ return db . login ( 'robin' , 'dickgrayson' ) ;
199
+ } ) . then ( function ( ) {
200
+ return db . putUser ( 'robin' , { metadata : { metadata : metadata } } ) ;
201
+ } ) . then ( function ( res ) {
202
+ res . ok . should . equal ( true ) ;
203
+ return db . getUser ( 'robin' ) ;
204
+ } ) . then ( function ( changedUser ) {
205
+ changedUser . metadata . should . deep . equal ( metadata ) ;
206
+ } ) . catch ( function ( err ) {
207
+ should . not . exist ( err ) ;
208
+ } ) ;
209
+ } ) ;
210
+
144
211
it ( 'Test wrong user for getUser' , function ( ) {
145
212
return db . signup ( 'robin' , 'dickgrayson' ) . then ( function ( res ) {
146
213
return db . signup ( 'aquaman' , 'sleeps_with_fishes' ) ;
0 commit comments