@@ -212,6 +212,105 @@ func TestCaptchaDiff(t *testing.T) {
212212 })
213213}
214214
215+ func TestPasskeyConfigMapping (t * testing.T ) {
216+ t .Run ("serializes passkey config to update body" , func (t * testing.T ) {
217+ c := newWithDefaults ()
218+ c .Passkey = & passkey {
219+ Enabled : true ,
220+ RpDisplayName : "Supabase CLI" ,
221+ RpId : "localhost" ,
222+ RpOrigins : []string {
223+ "http://127.0.0.1:3000" ,
224+ "https://localhost:3000" ,
225+ },
226+ }
227+ // Run test
228+ body := c .ToUpdateAuthConfigBody ()
229+ // Check result
230+ if assert .NotNil (t , body .PasskeyEnabled ) {
231+ assert .True (t , * body .PasskeyEnabled )
232+ }
233+ assert .Equal (t , "Supabase CLI" , ValOrDefault (body .WebauthnRpDisplayName , "" ))
234+ assert .Equal (t , "localhost" , ValOrDefault (body .WebauthnRpId , "" ))
235+ assert .Equal (t , "http://127.0.0.1:3000,https://localhost:3000" , ValOrDefault (body .WebauthnRpOrigins , "" ))
236+ })
237+
238+ t .Run ("does not serialize rp fields when passkey is disabled" , func (t * testing.T ) {
239+ c := newWithDefaults ()
240+ c .Passkey = & passkey {
241+ Enabled : false ,
242+ RpDisplayName : "Supabase CLI" ,
243+ RpId : "localhost" ,
244+ RpOrigins : []string {"http://127.0.0.1:3000" },
245+ }
246+ // Run test
247+ body := c .ToUpdateAuthConfigBody ()
248+ // Check result
249+ if assert .NotNil (t , body .PasskeyEnabled ) {
250+ assert .False (t , * body .PasskeyEnabled )
251+ }
252+ _ , err := body .WebauthnRpDisplayName .Get ()
253+ assert .Error (t , err )
254+ _ , err = body .WebauthnRpId .Get ()
255+ assert .Error (t , err )
256+ _ , err = body .WebauthnRpOrigins .Get ()
257+ assert .Error (t , err )
258+ })
259+
260+ t .Run ("hydrates passkey config from remote" , func (t * testing.T ) {
261+ c := newWithDefaults ()
262+ c .Passkey = & passkey {
263+ Enabled : true ,
264+ }
265+ // Run test
266+ c .FromRemoteAuthConfig (v1API.AuthConfigResponse {
267+ PasskeyEnabled : true ,
268+ WebauthnRpDisplayName : nullable .NewNullableWithValue ("Supabase CLI" ),
269+ WebauthnRpId : nullable .NewNullableWithValue ("localhost" ),
270+ WebauthnRpOrigins : nullable .NewNullableWithValue ("http://127.0.0.1:3000,https://localhost:3000" ),
271+ })
272+ // Check result
273+ if assert .NotNil (t , c .Passkey ) {
274+ assert .True (t , c .Passkey .Enabled )
275+ assert .Equal (t , "Supabase CLI" , c .Passkey .RpDisplayName )
276+ assert .Equal (t , "localhost" , c .Passkey .RpId )
277+ assert .Equal (t , []string {
278+ "http://127.0.0.1:3000" ,
279+ "https://localhost:3000" ,
280+ }, c .Passkey .RpOrigins )
281+ }
282+ })
283+
284+ t .Run ("ignores remote settings when local passkey config is undefined" , func (t * testing.T ) {
285+ c := newWithDefaults ()
286+ // Run test
287+ c .FromRemoteAuthConfig (v1API.AuthConfigResponse {
288+ PasskeyEnabled : true ,
289+ WebauthnRpDisplayName : nullable .NewNullableWithValue ("Supabase CLI" ),
290+ WebauthnRpId : nullable .NewNullableWithValue ("localhost" ),
291+ WebauthnRpOrigins : nullable .NewNullableWithValue ("http://127.0.0.1:3000" ),
292+ })
293+ // Check result
294+ assert .Nil (t , c .Passkey )
295+ })
296+ }
297+
298+ func TestPasskeyDiff (t * testing.T ) {
299+ t .Run ("ignores undefined config" , func (t * testing.T ) {
300+ c := newWithDefaults ()
301+ // Run test
302+ diff , err := c .DiffWithRemote (v1API.AuthConfigResponse {
303+ PasskeyEnabled : true ,
304+ WebauthnRpDisplayName : nullable .NewNullableWithValue ("Supabase CLI" ),
305+ WebauthnRpId : nullable .NewNullableWithValue ("localhost" ),
306+ WebauthnRpOrigins : nullable .NewNullableWithValue ("http://127.0.0.1:3000" ),
307+ })
308+ // Check error
309+ assert .NoError (t , err )
310+ assert .Empty (t , string (diff ))
311+ })
312+ }
313+
215314func TestHookDiff (t * testing.T ) {
216315 t .Run ("local and remote enabled" , func (t * testing.T ) {
217316 c := newWithDefaults ()
0 commit comments