@@ -1754,17 +1754,15 @@ describe('Auth Adapter features', () => {
1754
1754
validateAppId : ( ) => Promise . resolve ( ) ,
1755
1755
validateAuthData : ( ) => Promise . resolve ( ) ,
1756
1756
} ;
1757
- const alwaysValidateAdapter = {
1757
+ const baseAdapter2 = {
1758
1758
validateAppId : ( ) => Promise . resolve ( ) ,
1759
1759
validateAuthData : ( ) => Promise . resolve ( ) ,
1760
1760
options : { anOption : true } ,
1761
- alwaysValidate : true ,
1762
1761
} ;
1763
1762
1764
1763
const doNotSaveAdapter = {
1765
1764
validateAppId : ( ) => Promise . resolve ( ) ,
1766
1765
validateAuthData : ( ) => Promise . resolve ( { doNotSave : true } ) ,
1767
- alwaysValidate : true ,
1768
1766
} ;
1769
1767
1770
1768
const additionalAdapter = {
@@ -1795,15 +1793,19 @@ describe('Auth Adapter features', () => {
1795
1793
validateLogin : ( ) => Promise . resolve ( ) ,
1796
1794
} ;
1797
1795
1796
+ const wrongAdapter = {
1797
+ validateAppId : ( ) => Promise . resolve ( ) ,
1798
+ } ;
1799
+
1798
1800
const headers = {
1799
1801
'Content-Type' : 'application/json' ,
1800
1802
'X-Parse-Application-Id' : 'test' ,
1801
1803
'X-Parse-REST-API-Key' : 'rest' ,
1802
1804
} ;
1803
1805
1804
1806
it ( 'should pass authData, options, req, user to validateAuthData' , async ( ) => {
1805
- spyOn ( alwaysValidateAdapter , 'validateAuthData' ) . and . resolveTo ( { } ) ;
1806
- await reconfigureServer ( { auth : { alwaysValidateAdapter } } ) ;
1807
+ spyOn ( baseAdapter , 'validateAuthData' ) . and . resolveTo ( { } ) ;
1808
+ await reconfigureServer ( { auth : { baseAdapter } } ) ;
1807
1809
1808
1810
const user = new Parse . User ( ) ;
1809
1811
@@ -1812,14 +1814,14 @@ describe('Auth Adapter features', () => {
1812
1814
await user . save ( {
1813
1815
username : 'test' ,
1814
1816
password : 'password' ,
1815
- authData : { alwaysValidateAdapter : payload } ,
1817
+ authData : { baseAdapter : payload } ,
1816
1818
} ) ;
1817
1819
1818
1820
expect ( user . getSessionToken ( ) ) . toBeDefined ( ) ;
1819
1821
1820
- const firstCall = alwaysValidateAdapter . validateAuthData . calls . argsFor ( 0 ) ;
1822
+ const firstCall = baseAdapter . validateAuthData . calls . argsFor ( 0 ) ;
1821
1823
expect ( firstCall [ 0 ] ) . toEqual ( payload ) ;
1822
- expect ( firstCall [ 1 ] ) . toEqual ( alwaysValidateAdapter ) ;
1824
+ expect ( firstCall [ 1 ] ) . toEqual ( baseAdapter ) ;
1823
1825
expect ( firstCall [ 2 ] . config ) . toBeDefined ( ) ;
1824
1826
expect ( firstCall [ 2 ] . config . headers ) . toBeDefined ( ) ;
1825
1827
expect ( firstCall [ 2 ] . auth ) . toBeDefined ( ) ;
@@ -1833,12 +1835,12 @@ describe('Auth Adapter features', () => {
1833
1835
body : JSON . stringify ( {
1834
1836
username : 'test' ,
1835
1837
password : 'password' ,
1836
- authData : { alwaysValidateAdapter : payload } ,
1838
+ authData : { baseAdapter : payload } ,
1837
1839
} ) ,
1838
1840
} ) ;
1839
- const secondCall = alwaysValidateAdapter . validateAuthData . calls . argsFor ( 1 ) ;
1841
+ const secondCall = baseAdapter . validateAuthData . calls . argsFor ( 1 ) ;
1840
1842
expect ( secondCall [ 0 ] ) . toEqual ( payload ) ;
1841
- expect ( secondCall [ 1 ] ) . toEqual ( alwaysValidateAdapter ) ;
1843
+ expect ( secondCall [ 1 ] ) . toEqual ( baseAdapter ) ;
1842
1844
expect ( secondCall [ 2 ] . config ) . toBeDefined ( ) ;
1843
1845
expect ( secondCall [ 2 ] . auth ) . toBeDefined ( ) ;
1844
1846
expect ( secondCall [ 2 ] . config . headers ) . toBeDefined ( ) ;
@@ -1945,7 +1947,18 @@ describe('Auth Adapter features', () => {
1945
1947
expect ( call [ 3 ] . id ) . toEqual ( user . id ) ;
1946
1948
expect ( user . getSessionToken ( ) ) . toBeDefined ( ) ;
1947
1949
} ) ;
1948
- xit ( 'should throw if no triggers found' ) ;
1950
+ it ( 'should throw if no triggers found' , async ( ) => {
1951
+ await reconfigureServer ( { auth : { wrongAdapter } } ) ;
1952
+ const user = new Parse . User ( ) ;
1953
+ try {
1954
+ await user . save ( { authData : { wrongAdapter : { id : 'wrongAdapter' } } } ) ;
1955
+ fail ( 'should throw' ) ;
1956
+ } catch ( e ) {
1957
+ expect ( e . message ) . toContain (
1958
+ 'Adapter not ready, need to implement validateAuthData or (validateSetUp, validateLogin, validateUpdate)'
1959
+ ) ;
1960
+ }
1961
+ } ) ;
1949
1962
it ( 'should not update authData if provider return doNotSave' , async ( ) => {
1950
1963
spyOn ( doNotSaveAdapter , 'validateAuthData' ) . and . resolveTo ( { doNotSave : true } ) ;
1951
1964
await reconfigureServer ( {
@@ -1962,23 +1975,23 @@ describe('Auth Adapter features', () => {
1962
1975
1963
1976
expect ( user . get ( 'authData' ) ) . toEqual ( { baseAdapter : { id : 'baseAdapter' } } ) ;
1964
1977
} ) ;
1965
- it ( 'should force authData validation if provider use alwaysValidate ' , async ( ) => {
1966
- spyOn ( alwaysValidateAdapter , 'validateAuthData' ) . and . resolveTo ( { } ) ;
1978
+ it ( 'should perform authData validation only when its required ' , async ( ) => {
1979
+ spyOn ( baseAdapter2 , 'validateAuthData' ) . and . resolveTo ( { } ) ;
1967
1980
spyOn ( baseAdapter , 'validateAuthData' ) . and . resolveTo ( { } ) ;
1968
1981
await reconfigureServer ( {
1969
- auth : { alwaysValidateAdapter , baseAdapter } ,
1982
+ auth : { baseAdapter2 , baseAdapter } ,
1970
1983
} ) ;
1971
1984
1972
1985
const user = new Parse . User ( ) ;
1973
1986
1974
1987
await user . save ( {
1975
1988
authData : {
1976
1989
baseAdapter : { id : 'baseAdapter' } ,
1977
- alwaysValidateAdapter : { token : true } ,
1990
+ baseAdapter2 : { token : true } ,
1978
1991
} ,
1979
1992
} ) ;
1980
1993
1981
- expect ( alwaysValidateAdapter . validateAuthData ) . toHaveBeenCalledTimes ( 1 ) ;
1994
+ expect ( baseAdapter2 . validateAuthData ) . toHaveBeenCalledTimes ( 1 ) ;
1982
1995
1983
1996
const user2 = new Parse . User ( ) ;
1984
1997
await user2 . save ( {
@@ -1987,17 +2000,17 @@ describe('Auth Adapter features', () => {
1987
2000
} ,
1988
2001
} ) ;
1989
2002
1990
- expect ( alwaysValidateAdapter . validateAuthData ) . toHaveBeenCalledTimes ( 1 ) ;
2003
+ expect ( baseAdapter2 . validateAuthData ) . toHaveBeenCalledTimes ( 1 ) ;
1991
2004
1992
2005
const user3 = new Parse . User ( ) ;
1993
2006
await user3 . save ( {
1994
2007
authData : {
1995
2008
baseAdapter : { id : 'baseAdapter' } ,
1996
- alwaysValidateAdapter : { token : true } ,
2009
+ baseAdapter2 : { token : true } ,
1997
2010
} ,
1998
2011
} ) ;
1999
2012
2000
- expect ( alwaysValidateAdapter . validateAuthData ) . toHaveBeenCalledTimes ( 2 ) ;
2013
+ expect ( baseAdapter2 . validateAuthData ) . toHaveBeenCalledTimes ( 2 ) ;
2001
2014
} ) ;
2002
2015
it ( 'should require additional provider if configured' , async ( ) => {
2003
2016
await reconfigureServer ( {
@@ -2061,26 +2074,26 @@ describe('Auth Adapter features', () => {
2061
2074
spyOn ( baseAdapter , 'validateAuthData' ) . and . resolveTo ( {
2062
2075
response : { someData : true } ,
2063
2076
} ) ;
2064
- spyOn ( alwaysValidateAdapter , 'validateAuthData' ) . and . resolveTo ( {
2077
+ spyOn ( baseAdapter2 , 'validateAuthData' ) . and . resolveTo ( {
2065
2078
response : { someData2 : true } ,
2066
2079
save : { otherData : true } ,
2067
2080
} ) ;
2068
2081
await reconfigureServer ( {
2069
- auth : { baseAdapter, alwaysValidateAdapter } ,
2082
+ auth : { baseAdapter, baseAdapter2 } ,
2070
2083
} ) ;
2071
2084
2072
2085
const user = new Parse . User ( ) ;
2073
2086
2074
2087
await user . save ( {
2075
2088
authData : {
2076
2089
baseAdapter : { id : 'baseAdapter' } ,
2077
- alwaysValidateAdapter : { test : true } ,
2090
+ baseAdapter2 : { test : true } ,
2078
2091
} ,
2079
2092
} ) ;
2080
2093
2081
2094
expect ( user . get ( 'authDataResponse' ) ) . toEqual ( {
2082
2095
baseAdapter : { someData : true } ,
2083
- alwaysValidateAdapter : { someData2 : true } ,
2096
+ baseAdapter2 : { someData2 : true } ,
2084
2097
} ) ;
2085
2098
2086
2099
const user2 = new Parse . User ( ) ;
@@ -2089,46 +2102,46 @@ describe('Auth Adapter features', () => {
2089
2102
{
2090
2103
authData : {
2091
2104
baseAdapter : { id : 'baseAdapter' } ,
2092
- alwaysValidateAdapter : { test : true } ,
2105
+ baseAdapter2 : { test : true } ,
2093
2106
} ,
2094
2107
} ,
2095
2108
{ sessionToken : user . getSessionToken ( ) }
2096
2109
) ;
2097
2110
2098
- expect ( user2 . get ( 'authDataResponse' ) ) . toEqual ( { alwaysValidateAdapter : { someData2 : true } } ) ;
2111
+ expect ( user2 . get ( 'authDataResponse' ) ) . toEqual ( { baseAdapter2 : { someData2 : true } } ) ;
2099
2112
2100
2113
const user3 = new Parse . User ( ) ;
2101
2114
await user3 . save ( {
2102
2115
authData : {
2103
2116
baseAdapter : { id : 'baseAdapter' } ,
2104
- alwaysValidateAdapter : { test : true } ,
2117
+ baseAdapter2 : { test : true } ,
2105
2118
} ,
2106
2119
} ) ;
2107
2120
2108
2121
// On logIn all authData are revalidated
2109
2122
expect ( user3 . get ( 'authDataResponse' ) ) . toEqual ( {
2110
2123
baseAdapter : { someData : true } ,
2111
- alwaysValidateAdapter : { someData2 : true } ,
2124
+ baseAdapter2 : { someData2 : true } ,
2112
2125
} ) ;
2113
2126
2114
2127
const userViaMasterKey = new Parse . User ( ) ;
2115
2128
userViaMasterKey . id = user2 . id ;
2116
2129
await userViaMasterKey . fetch ( { useMasterKey : true } ) ;
2117
2130
expect ( userViaMasterKey . get ( 'authData' ) ) . toEqual ( {
2118
2131
baseAdapter : { id : 'baseAdapter' } ,
2119
- alwaysValidateAdapter : { otherData : true } ,
2132
+ baseAdapter2 : { otherData : true } ,
2120
2133
} ) ;
2121
2134
} ) ;
2122
2135
it ( 'should return authData response and save some info on username login' , async ( ) => {
2123
2136
spyOn ( baseAdapter , 'validateAuthData' ) . and . resolveTo ( {
2124
2137
response : { someData : true } ,
2125
2138
} ) ;
2126
- spyOn ( alwaysValidateAdapter , 'validateAuthData' ) . and . resolveTo ( {
2139
+ spyOn ( baseAdapter2 , 'validateAuthData' ) . and . resolveTo ( {
2127
2140
response : { someData2 : true } ,
2128
2141
save : { otherData : true } ,
2129
2142
} ) ;
2130
2143
await reconfigureServer ( {
2131
- auth : { baseAdapter, alwaysValidateAdapter } ,
2144
+ auth : { baseAdapter, baseAdapter2 } ,
2132
2145
} ) ;
2133
2146
2134
2147
const user = new Parse . User ( ) ;
@@ -2138,13 +2151,13 @@ describe('Auth Adapter features', () => {
2138
2151
password : 'password' ,
2139
2152
authData : {
2140
2153
baseAdapter : { id : 'baseAdapter' } ,
2141
- alwaysValidateAdapter : { test : true } ,
2154
+ baseAdapter2 : { test : true } ,
2142
2155
} ,
2143
2156
} ) ;
2144
2157
2145
2158
expect ( user . get ( 'authDataResponse' ) ) . toEqual ( {
2146
2159
baseAdapter : { someData : true } ,
2147
- alwaysValidateAdapter : { someData2 : true } ,
2160
+ baseAdapter2 : { someData2 : true } ,
2148
2161
} ) ;
2149
2162
2150
2163
const res = await request ( {
@@ -2155,36 +2168,36 @@ describe('Auth Adapter features', () => {
2155
2168
username : 'username' ,
2156
2169
password : 'password' ,
2157
2170
authData : {
2158
- alwaysValidateAdapter : { test : true } ,
2171
+ baseAdapter2 : { test : true } ,
2159
2172
baseAdapter : { id : 'baseAdapter' } ,
2160
2173
} ,
2161
2174
} ) ,
2162
2175
} ) ;
2163
2176
const result = JSON . parse ( res . text ) ;
2164
2177
expect ( result . authDataResponse ) . toEqual ( {
2165
- alwaysValidateAdapter : { someData2 : true } ,
2178
+ baseAdapter2 : { someData2 : true } ,
2166
2179
baseAdapter : { someData : true } ,
2167
2180
} ) ;
2168
2181
2169
2182
await user . fetch ( { useMasterKey : true } ) ;
2170
2183
expect ( user . get ( 'authData' ) ) . toEqual ( {
2171
2184
baseAdapter : { id : 'baseAdapter' } ,
2172
- alwaysValidateAdapter : { otherData : true } ,
2185
+ baseAdapter2 : { otherData : true } ,
2173
2186
} ) ;
2174
2187
} ) ;
2175
2188
it ( 'should allow update of authData' , async ( ) => {
2176
2189
spyOn ( baseAdapter , 'validateAuthData' ) . and . resolveTo ( {
2177
2190
response : { someData : true } ,
2178
2191
} ) ;
2179
- spyOn ( alwaysValidateAdapter , 'validateAuthData' ) . and . resolveTo ( {
2192
+ spyOn ( baseAdapter2 , 'validateAuthData' ) . and . resolveTo ( {
2180
2193
response : { someData2 : true } ,
2181
2194
save : { otherData : true } ,
2182
2195
} ) ;
2183
2196
await reconfigureServer ( {
2184
- auth : { baseAdapter, alwaysValidateAdapter } ,
2197
+ auth : { baseAdapter, baseAdapter2 } ,
2185
2198
} ) ;
2186
2199
await reconfigureServer ( {
2187
- auth : { baseAdapter, alwaysValidateAdapter } ,
2200
+ auth : { baseAdapter, baseAdapter2 } ,
2188
2201
} ) ;
2189
2202
2190
2203
const user = new Parse . User ( ) ;
@@ -2194,7 +2207,7 @@ describe('Auth Adapter features', () => {
2194
2207
password : 'password' ,
2195
2208
authData : {
2196
2209
baseAdapter : { id : 'baseAdapter' } ,
2197
- alwaysValidateAdapter : { test : true } ,
2210
+ baseAdapter2 : { test : true } ,
2198
2211
} ,
2199
2212
} ) ;
2200
2213
expect ( baseAdapter . validateAuthData ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -2206,7 +2219,7 @@ describe('Auth Adapter features', () => {
2206
2219
await user . save (
2207
2220
{
2208
2221
authData : {
2209
- alwaysValidateAdapter : { test : true } ,
2222
+ baseAdapter2 : { test : true } ,
2210
2223
baseAdapter : { id : 'baseAdapter' } ,
2211
2224
} ,
2212
2225
} ,
@@ -2220,7 +2233,7 @@ describe('Auth Adapter features', () => {
2220
2233
await user . save (
2221
2234
{
2222
2235
authData : {
2223
- alwaysValidateAdapter : { test : true } ,
2236
+ baseAdapter2 : { test : true } ,
2224
2237
baseAdapter : { id : 'baseAdapter' } ,
2225
2238
} ,
2226
2239
} ,
@@ -2233,7 +2246,7 @@ describe('Auth Adapter features', () => {
2233
2246
await user . save (
2234
2247
{
2235
2248
authData : {
2236
- alwaysValidateAdapter : { test : true } ,
2249
+ baseAdapter2 : { test : true } ,
2237
2250
baseAdapter : { id : 'baseAdapter2' } ,
2238
2251
} ,
2239
2252
} ,
@@ -2246,7 +2259,7 @@ describe('Auth Adapter features', () => {
2246
2259
await user . save (
2247
2260
{
2248
2261
authData : {
2249
- alwaysValidateAdapter : { test : true } ,
2262
+ baseAdapter2 : { test : true } ,
2250
2263
baseAdapter : { id : 'baseAdapter3' } ,
2251
2264
} ,
2252
2265
} ,
@@ -2258,12 +2271,12 @@ describe('Auth Adapter features', () => {
2258
2271
await user . fetch ( { useMasterKey : true } ) ;
2259
2272
expect ( user . get ( 'authData' ) ) . toEqual ( {
2260
2273
baseAdapter : { id : 'baseAdapter3' } ,
2261
- alwaysValidateAdapter : { otherData : true } ,
2274
+ baseAdapter2 : { otherData : true } ,
2262
2275
} ) ;
2263
2276
} ) ;
2264
2277
it ( 'should pass user to auth adapter on update by matching session' , async ( ) => {
2265
- spyOn ( alwaysValidateAdapter , 'validateAuthData' ) . and . resolveTo ( { } ) ;
2266
- await reconfigureServer ( { auth : { alwaysValidateAdapter } } ) ;
2278
+ spyOn ( baseAdapter2 , 'validateAuthData' ) . and . resolveTo ( { } ) ;
2279
+ await reconfigureServer ( { auth : { baseAdapter2 } } ) ;
2267
2280
2268
2281
const user = new Parse . User ( ) ;
2269
2282
@@ -2277,24 +2290,24 @@ describe('Auth Adapter features', () => {
2277
2290
expect ( user . getSessionToken ( ) ) . toBeDefined ( ) ;
2278
2291
2279
2292
await user . save (
2280
- { authData : { alwaysValidateAdapter : payload } } ,
2293
+ { authData : { baseAdapter2 : payload } } ,
2281
2294
{ sessionToken : user . getSessionToken ( ) }
2282
2295
) ;
2283
2296
2284
- const firstCall = alwaysValidateAdapter . validateAuthData . calls . argsFor ( 0 ) ;
2297
+ const firstCall = baseAdapter2 . validateAuthData . calls . argsFor ( 0 ) ;
2285
2298
expect ( firstCall [ 0 ] ) . toEqual ( payload ) ;
2286
- expect ( firstCall [ 1 ] ) . toEqual ( alwaysValidateAdapter ) ;
2299
+ expect ( firstCall [ 1 ] ) . toEqual ( baseAdapter2 ) ;
2287
2300
expect ( firstCall [ 2 ] . config ) . toBeDefined ( ) ;
2288
2301
expect ( firstCall [ 2 ] . auth ) . toBeDefined ( ) ;
2289
2302
expect ( firstCall [ 2 ] . config . headers ) . toBeDefined ( ) ;
2290
2303
expect ( firstCall [ 3 ] instanceof Parse . User ) . toBeTruthy ( ) ;
2291
2304
expect ( firstCall [ 3 ] . id ) . toEqual ( user . id ) ;
2292
2305
2293
- await user . save ( { authData : { alwaysValidateAdapter : payload } } , { useMasterKey : true } ) ;
2306
+ await user . save ( { authData : { baseAdapter2 : payload } } , { useMasterKey : true } ) ;
2294
2307
2295
- const secondCall = alwaysValidateAdapter . validateAuthData . calls . argsFor ( 1 ) ;
2308
+ const secondCall = baseAdapter2 . validateAuthData . calls . argsFor ( 1 ) ;
2296
2309
expect ( secondCall [ 0 ] ) . toEqual ( payload ) ;
2297
- expect ( secondCall [ 1 ] ) . toEqual ( alwaysValidateAdapter ) ;
2310
+ expect ( secondCall [ 1 ] ) . toEqual ( baseAdapter2 ) ;
2298
2311
expect ( secondCall [ 2 ] . config ) . toBeDefined ( ) ;
2299
2312
expect ( secondCall [ 2 ] . auth ) . toBeDefined ( ) ;
2300
2313
expect ( secondCall [ 2 ] . config . headers ) . toBeDefined ( ) ;
0 commit comments