TestAdminUserDeleteFactor tests API /admin/users/ /factors/ /
()
| 781 | |
| 782 | // TestAdminUserDeleteFactor tests API /admin/users/<user_id>/factors/<factor_id>/ |
| 783 | func (ts *AdminTestSuite) TestAdminUserDeleteFactor() { |
| 784 | u, err := models.NewUser("123456789", "test-delete@example.com", "test", ts.Config.JWT.Aud, nil) |
| 785 | require.NoError(ts.T(), err, "Error making new user") |
| 786 | require.NoError(ts.T(), ts.API.db.Create(u), "Error creating user") |
| 787 | |
| 788 | f := models.NewTOTPFactor(u, "testSimpleName") |
| 789 | require.NoError(ts.T(), f.UpdateStatus(ts.API.db, models.FactorStateVerified)) |
| 790 | require.NoError(ts.T(), f.SetSecret("secretkey", ts.Config.Security.DBEncryption.Encrypt, ts.Config.Security.DBEncryption.EncryptionKeyID, ts.Config.Security.DBEncryption.EncryptionKey)) |
| 791 | require.NoError(ts.T(), ts.API.db.Create(f), "Error saving new test factor") |
| 792 | |
| 793 | // Setup request |
| 794 | w := httptest.NewRecorder() |
| 795 | req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("/admin/users/%s/factors/%s/", u.ID, f.ID), nil) |
| 796 | |
| 797 | req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", ts.token)) |
| 798 | |
| 799 | ts.API.handler.ServeHTTP(w, req) |
| 800 | require.Equal(ts.T(), http.StatusOK, w.Code) |
| 801 | |
| 802 | _, err = models.FindFactorByFactorID(ts.API.db, f.ID) |
| 803 | require.EqualError(ts.T(), err, models.FactorNotFoundError{}.Error()) |
| 804 | |
| 805 | } |
| 806 | |
| 807 | // TestAdminUserGetFactor tests API /admin/user/<user_id>/factors/ |
| 808 | func (ts *AdminTestSuite) TestAdminUserGetFactors() { |
nothing calls this directly
no test coverage detected