Skip to content

Commit

Permalink
refactor: pluralize factors endpoint, use lowercase totp (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Oct 18, 2022
1 parent a6a1874 commit 204bb87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func NewAPIWithVersion(ctx context.Context, globalConfig *conf.GlobalConfigurati
})

if api.config.MFA.Enabled {
r.With(api.requireAuthentication).Route("/factor", func(r *router) {
r.With(api.requireAuthentication).Route("/factors", func(r *router) {
r.Post("/", api.EnrollFactor)
r.Route("/{factor_id}", func(r *router) {
r.Use(api.loadFactor)
Expand Down Expand Up @@ -164,7 +164,7 @@ func NewAPIWithVersion(ctx context.Context, globalConfig *conf.GlobalConfigurati
r.Route("/{user_id}", func(r *router) {
r.Use(api.loadUser)
if api.config.MFA.Enabled {
r.Route("/factor", func(r *router) {
r.Route("/factors", func(r *router) {
r.Get("/", api.adminUserGetFactors)
r.Route("/{factor_id}", func(r *router) {
r.Use(api.loadFactor)
Expand Down
2 changes: 1 addition & 1 deletion api/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type TOTPObject struct {
type EnrollFactorResponse struct {
ID uuid.UUID `json:"id"`
Type string `json:"type"`
TOTP TOTPObject `json:"TOTP,omitempty"`
TOTP TOTPObject `json:"totp,omitempty"`
}

type VerifyFactorParams struct {
Expand Down
16 changes: 8 additions & 8 deletions api/mfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (ts *MFATestSuite) TestEnrollFactor() {
require.NoError(ts.T(), err)

w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodPost, "/factor", &buffer)
req := httptest.NewRequest(http.MethodPost, "/factors", &buffer)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Set("Content-Type", "application/json")
ts.API.handler.ServeHTTP(w, req)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (ts *MFATestSuite) TestChallengeFactor() {
require.NoError(ts.T(), err, "Error generating access token")

var buffer bytes.Buffer
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost/factor/%s/challenge", f.ID), &buffer)
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost/factors/%s/challenge", f.ID), &buffer)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

Expand Down Expand Up @@ -226,7 +226,7 @@ func (ts *MFATestSuite) TestMFAVerifyFactor() {
require.NoError(ts.T(), err)

w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/factor/%s/verify", f.ID), &buffer)
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/factors/%s/verify", f.ID), &buffer)
testIPAddress := utilities.GetIPAddress(req)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
c, err := models.NewChallenge(f, testIPAddress)
Expand Down Expand Up @@ -319,7 +319,7 @@ func (ts *MFATestSuite) TestUnenrollVerifiedFactor() {
require.NoError(ts.T(), err)

w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("/factor/%s/", f.ID), &buffer)
req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("/factors/%s/", f.ID), &buffer)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
ts.API.handler.ServeHTTP(w, req)
require.Equal(ts.T(), v.expectedHTTPCode, w.Code)
Expand Down Expand Up @@ -362,7 +362,7 @@ func (ts *MFATestSuite) TestUnenrollUnverifiedFactor() {
}))

w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("/factor/%s", f.ID), &buffer)
req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("/factors/%s", f.ID), &buffer)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
ts.API.handler.ServeHTTP(w, req)
require.Equal(ts.T(), http.StatusOK, w.Code)
Expand Down Expand Up @@ -463,7 +463,7 @@ func enrollAndVerify(ts *MFATestSuite, user *models.User, token string) (verifyR
w := httptest.NewRecorder()
require.NoError(ts.T(), json.NewEncoder(&buffer).Encode(map[string]string{"friendly_name": "john", "factor_type": models.TOTP, "issuer": ts.TestDomain}))

req := httptest.NewRequest(http.MethodPost, "http://localhost/factor/", &buffer)
req := httptest.NewRequest(http.MethodPost, "http://localhost/factors/", &buffer)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Set("Content-Type", "application/json")

Expand All @@ -476,7 +476,7 @@ func enrollAndVerify(ts *MFATestSuite, user *models.User, token string) (verifyR
// Challenge
var challengeBuffer bytes.Buffer
x := httptest.NewRecorder()
req = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost/factor/%s/challenge", factorID), &challengeBuffer)
req = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost/factors/%s/challenge", factorID), &challengeBuffer)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Set("Content-Type", "application/json")
ts.API.handler.ServeHTTP(x, req)
Expand Down Expand Up @@ -505,7 +505,7 @@ func enrollAndVerify(ts *MFATestSuite, user *models.User, token string) (verifyR
"challenge_id": challengeID,
"code": code,
}))
req = httptest.NewRequest(http.MethodPost, fmt.Sprintf("/factor/%s/verify", factorID), &verifyBuffer)
req = httptest.NewRequest(http.MethodPost, fmt.Sprintf("/factors/%s/verify", factorID), &verifyBuffer)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Set("Content-Type", "application/json")

Expand Down

0 comments on commit 204bb87

Please sign in to comment.