MCPcopy Create free account
hub / github.com/supabase/auth / TestAdminUserUpdateFactor

Method TestAdminUserUpdateFactor

internal/api/admin_test.go:830–872  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

828}
829
830func (ts *AdminTestSuite) TestAdminUserUpdateFactor() {
831 u, err := models.NewUser("123456789", "test-delete@example.com", "test", ts.Config.JWT.Aud, nil)
832 require.NoError(ts.T(), err, "Error making new user")
833 require.NoError(ts.T(), ts.API.db.Create(u), "Error creating user")
834
835 f := models.NewPhoneFactor(u, "123456789", "testSimpleName")
836 require.NoError(ts.T(), f.SetSecret("secretkey", ts.Config.Security.DBEncryption.Encrypt, ts.Config.Security.DBEncryption.EncryptionKeyID, ts.Config.Security.DBEncryption.EncryptionKey))
837 require.NoError(ts.T(), ts.API.db.Create(f), "Error saving new test factor")
838
839 var cases = []struct {
840 Desc string
841 FactorData map[string]interface{}
842 ExpectedCode int
843 }{
844 {
845 Desc: "Update Factor friendly name",
846 FactorData: map[string]interface{}{
847 "friendly_name": "john",
848 },
849 ExpectedCode: http.StatusOK,
850 },
851 {
852 Desc: "Update Factor phone number",
853 FactorData: map[string]interface{}{
854 "phone": "+1976154321",
855 },
856 ExpectedCode: http.StatusOK,
857 },
858 }
859
860 // Initialize factor data
861 for _, c := range cases {
862 ts.Run(c.Desc, func() {
863 var buffer bytes.Buffer
864 require.NoError(ts.T(), json.NewEncoder(&buffer).Encode(c.FactorData))
865 w := httptest.NewRecorder()
866 req := httptest.NewRequest(http.MethodPut, fmt.Sprintf("/admin/users/%s/factors/%s/", u.ID, f.ID), &buffer)
867 req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", ts.token))
868 ts.API.handler.ServeHTTP(w, req)
869 require.Equal(ts.T(), c.ExpectedCode, w.Code)
870 })
871 }
872}
873
874func (ts *AdminTestSuite) TestAdminUserCreateValidationErrors() {
875 cases := []struct {

Callers

nothing calls this directly

Calls 8

NewUserFunction · 0.92
NewPhoneFactorFunction · 0.92
SetSecretMethod · 0.80
EncodeMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected