Skip to content

Commit

Permalink
Updated Naming convention and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
developerkunal committed Sep 23, 2024
1 parent a58d57f commit 2638241
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 32 deletions.
12 changes: 6 additions & 6 deletions authentication/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func (m *MFA) VerifyWithRecoveryCode(ctx context.Context, body mfa.VerifyWithRec
return
}

// AddAnAuthenticator Associates or adds a new authenticator for multi-factor authentication (MFA).
// AddAuthenticator Associates or adds a new authenticator for multi-factor authentication (MFA).
//
// See: https://auth0.com/docs/api/authentication#add-an-authenticator
func (m *MFA) AddAnAuthenticator(ctx context.Context, accessOrMfaToken string, body mfa.AddAnAuthenticatorRequest, opts ...RequestOption) (a *mfa.AddAnAuthenticatorResponse, err error) {
func (m *MFA) AddAuthenticator(ctx context.Context, accessOrMfaToken string, body mfa.AddAuthenticatorRequest, opts ...RequestOption) (a *mfa.AddAuthenticatorResponse, err error) {
opts = append(opts, Header("Authorization", "Bearer "+accessOrMfaToken))
missing := []string{}
check(&missing, "ClientID", (body.ClientID != "" || m.authentication.clientID != ""))
Expand All @@ -159,16 +159,16 @@ func (m *MFA) AddAnAuthenticator(ctx context.Context, accessOrMfaToken string, b
// ListAuthenticators Returns a list of authenticators associated with your application.
//
// See: https://auth0.com/docs/api/authentication#list-authenticators
func (m *MFA) ListAuthenticators(ctx context.Context, accessToken string, opts ...RequestOption) (a []mfa.ListAuthenticatorsResponse, err error) {
opts = append(opts, Header("Authorization", "Bearer "+accessToken))
func (m *MFA) ListAuthenticators(ctx context.Context, accessOrMfaToken string, opts ...RequestOption) (a []mfa.ListAuthenticatorsResponse, err error) {
opts = append(opts, Header("Authorization", "Bearer "+accessOrMfaToken))
err = m.authentication.Request(ctx, "GET", m.authentication.URI("mfa", "authenticators"), nil, &a, opts...)
return
}

// DeleteAnAuthenticator Deletes an associated authenticator using its ID.
// DeleteAuthenticator Deletes an associated authenticator using its ID.
//
// See: https://auth0.com/docs/api/authentication#delete-an-authenticator
func (m *MFA) DeleteAnAuthenticator(ctx context.Context, accessToken string, authenticatorID string, opts ...RequestOption) (err error) {
func (m *MFA) DeleteAuthenticator(ctx context.Context, accessToken string, authenticatorID string, opts ...RequestOption) (err error) {
opts = append(opts, Header("Authorization", "Bearer "+accessToken))
err = m.authentication.Request(ctx, "DELETE", m.authentication.URI("mfa", "authenticators", authenticatorID), nil, nil, opts...)
return
Expand Down
8 changes: 4 additions & 4 deletions authentication/mfa/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type VerifyWithRecoveryCodeResponse struct {
RecoveryCode string `json:"recovery_code,omitempty"`
}

// AddAnAuthenticatorRequest defines the request body for adding an authenticator.
type AddAnAuthenticatorRequest struct {
// AddAuthenticatorRequest defines the request body for adding an authenticator.
type AddAuthenticatorRequest struct {
oauth.ClientAuthentication
// The type of authenticators supported by the client.
// An array with values "otp" or "oob".
Expand All @@ -76,8 +76,8 @@ type AddAnAuthenticatorRequest struct {
PhoneNumber string `json:"phone_number,omitempty"`
}

// AddAnAuthenticatorResponse defines the response when adding an authenticator.
type AddAnAuthenticatorResponse struct {
// AddAuthenticatorResponse defines the response when adding an authenticator.
type AddAuthenticatorResponse struct {
// If present, the OOB code that should be presented to the user to verify the authenticator.
OOBCode string `json:"oob_code,omitempty"`
// If present, a new recovery code that should be presented to the user to store.
Expand Down
39 changes: 17 additions & 22 deletions authentication/mfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,27 @@ func TestMFAVerifyWithRecoveryCode(t *testing.T) {
})
}

func TestMFA_AddAnAuthenticator(t *testing.T) {
func TestMFAAddAuthenticator(t *testing.T) {
t.Run("Should require ClientID, AuthenticatorTypes", func(t *testing.T) {
auth, err := New(
context.Background(),
domain,
)
require.NoError(t, err)

_, err = auth.MFA.AddAnAuthenticator(context.Background(),
_, err = auth.MFA.AddAuthenticator(context.Background(),
"mfa-token",
mfa.AddAnAuthenticatorRequest{})
mfa.AddAuthenticatorRequest{})
assert.ErrorContains(t, err, "Missing required fields: ClientID, AuthenticatorTypes")
})

t.Run("Should return response for OOB (SMS channel)", func(t *testing.T) {
skipE2E(t)
configureHTTPTestRecordings(t, authAPI)

response, err := authAPI.MFA.AddAnAuthenticator(context.Background(),
response, err := authAPI.MFA.AddAuthenticator(context.Background(),
"mfa-token",
mfa.AddAnAuthenticatorRequest{
mfa.AddAuthenticatorRequest{
ClientAuthentication: oauth.ClientAuthentication{
ClientSecret: clientSecret,
},
Expand All @@ -216,9 +216,9 @@ func TestMFA_AddAnAuthenticator(t *testing.T) {
skipE2E(t)
configureHTTPTestRecordings(t, authAPI)

response, err := authAPI.MFA.AddAnAuthenticator(context.Background(),
response, err := authAPI.MFA.AddAuthenticator(context.Background(),
"mfa-token",
mfa.AddAnAuthenticatorRequest{
mfa.AddAuthenticatorRequest{
ClientAuthentication: oauth.ClientAuthentication{
ClientSecret: clientSecret,
},
Expand All @@ -236,9 +236,9 @@ func TestMFA_AddAnAuthenticator(t *testing.T) {
skipE2E(t)
configureHTTPTestRecordings(t, authAPI)

response, err := authAPI.MFA.AddAnAuthenticator(context.Background(),
response, err := authAPI.MFA.AddAuthenticator(context.Background(),
"mfa-token",
mfa.AddAnAuthenticatorRequest{
mfa.AddAuthenticatorRequest{
ClientAuthentication: oauth.ClientAuthentication{
ClientSecret: clientSecret,
},
Expand All @@ -252,7 +252,7 @@ func TestMFA_AddAnAuthenticator(t *testing.T) {
})
}

func TestMFA_ListAuthenticators(t *testing.T) {
func TestMFAListAuthenticators(t *testing.T) {
skipE2E(t)
configureHTTPTestRecordings(t, authAPI)

Expand All @@ -263,17 +263,12 @@ func TestMFA_ListAuthenticators(t *testing.T) {
assert.NotEmpty(t, authenticators)
}

/*func TestMFA_DeleteAnAuthenticator(t *testing.T) {
t.Run("Should return no error for a valid request", func(t *testing.T) {
skipE2E(t)
configureHTTPTestRecordings(t, authAPI)
err := authAPI.MFA.DeleteAnAuthenticator(context.Background(),
"access-token",
"push|dev_BBTKYpxKHOXVBnql")
func TestMFADeleteAuthenticator(t *testing.T) {
skipE2E(t)
configureHTTPTestRecordings(t, authAPI)

require.NoError(t, err)
})
err := authAPI.MFA.DeleteAuthenticator(context.Background(),
"mfa-token",
"push|dev_BBTKYpxKHOXVBnql")
require.NoError(t, err)
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
version: 2
interactions:
- id: 0
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 0
transfer_encoding: []
trailer: {}
host: go-auth0-dev.eu.auth0.com
remote_addr: ""
request_uri: ""
body: ""
form: {}
headers:
Content-Type:
- application/json
url: https://go-auth0-dev.eu.auth0.com/mfa/authenticators/push%7Cdev_BBTKYpxKHOXVBnql
method: DELETE
response:
proto: HTTP/2.0
proto_major: 2
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: 107
uncompressed: false
body: ""
headers:
Content-Type:
- application/json
status: 204 No Content
code: 204
duration: 252.26575ms

0 comments on commit 2638241

Please sign in to comment.