Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DXCDT-175] Add read and update to Duo Settings #84

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions management/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ func (m *MultiFactorEmail) Enable(enabled bool, opts ...RequestOption) error {
}, opts...)
}

// MultiFactorDUOSettings holds settings for configuring DUO.
type MultiFactorDUOSettings struct {
Hostname *string `json:"host,omitempty"`
IntegrationKey *string `json:"ikey,omitempty"`
SecretKey *string `json:"skey,omitempty"`
}

// MultiFactorDUO is used for Duo MFA.
type MultiFactorDUO struct{ *Management }

Expand All @@ -354,6 +361,21 @@ func (m *MultiFactorDUO) Enable(enabled bool, opts ...RequestOption) error {
}, opts...)
}

// Read WebAuthn Roaming Multi-factor Authentication Settings.
//
// See: https://auth0.com/docs/secure/multi-factor-authentication/configure-cisco-duo-for-mfa
func (m *MultiFactorDUO) Read(opts ...RequestOption) (s *MultiFactorDUOSettings, err error) {
err = m.Request("GET", m.URI("guardian", "factors", "duo", "settings"), &s, opts...)
return
}

// Update WebAuthn Roaming Multi-factor Authentication Settings.
//
// See: https://auth0.com/docs/secure/multi-factor-authentication/configure-cisco-duo-for-mfa
func (m *MultiFactorDUO) Update(s *MultiFactorDUOSettings, opts ...RequestOption) error {
return m.Request("PUT", m.URI("guardian", "factors", "duo", "settings"), &s, opts...)
}

// MultiFactorWebAuthnSettings holds settings for
// configuring WebAuthn Roaming or Platform.
type MultiFactorWebAuthnSettings struct {
Expand Down
46 changes: 36 additions & 10 deletions management/guardian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,46 @@ func TestGuardian(t *testing.T) {
assertMFAIsEnabled(t, "email")
})

t.Run("DUO Enable", func(t *testing.T) {
setupHTTPRecordings(t)
t.Run("DUO", func(t *testing.T) {
t.Run("Enable", func(t *testing.T) {
setupHTTPRecordings(t)

initialStatus, err := getInitialMFAStatus("duo")
assert.NoError(t, err)
initialStatus, err := getInitialMFAStatus("duo")
assert.NoError(t, err)

t.Cleanup(func() {
err := m.Guardian.MultiFactor.DUO.Enable(initialStatus)
require.NoError(t, err)
t.Cleanup(func() {
err := m.Guardian.MultiFactor.DUO.Enable(initialStatus)
require.NoError(t, err)
})

err = m.Guardian.MultiFactor.DUO.Enable(true)
assert.NoError(t, err)
assertMFAIsEnabled(t, "duo")
})
t.Run("Settings", func(t *testing.T) {
setupHTTPRecordings(t)

err = m.Guardian.MultiFactor.DUO.Enable(true)
assert.NoError(t, err)
assertMFAIsEnabled(t, "duo")
initialSettings, err := m.Guardian.MultiFactor.DUO.Read()
assert.NoError(t, err)
t.Cleanup(func() {
err := m.Guardian.MultiFactor.DUO.Update(initialSettings)
require.NoError(t, err)
})

updatedSettings := &MultiFactorDUOSettings{
Hostname: auth0.String("api-hostname"),
IntegrationKey: auth0.String("someKey"),
SecretKey: auth0.String("someSecret"),
}
err = m.Guardian.MultiFactor.DUO.Update(updatedSettings)
assert.NoError(t, err)

actualSettings, err := m.Guardian.MultiFactor.DUO.Read()
assert.NoError(t, err)
assert.Equal(t, "api-hostname", actualSettings.GetHostname())
assert.Equal(t, "someKey", actualSettings.GetIntegrationKey())
assert.Equal(t, "someSecret", actualSettings.GetSecretKey())
})
})

t.Run("OTP Enable", func(t *testing.T) {
Expand Down
29 changes: 29 additions & 0 deletions management/management.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions management/management.gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interactions:
url: https://go-auth0-dev.eu.auth0.com/api/v2/guardian/factors
method: GET
response:
body: '[{"name":"sms","enabled":true,"trial_expired":false},{"name":"push-notification","enabled":false,"trial_expired":false},{"name":"otp","enabled":false,"trial_expired":false},{"name":"email","enabled":false,"trial_expired":false},{"name":"duo","enabled":false,"trial_expired":false},{"name":"webauthn-roaming","enabled":false,"trial_expired":false},{"name":"webauthn-platform","enabled":false,"trial_expired":false},{"name":"recovery-code","enabled":false,"trial_expired":false}]'
body: '[{"name":"sms","enabled":false,"trial_expired":false},{"name":"push-notification","enabled":false,"trial_expired":false},{"name":"otp","enabled":false,"trial_expired":false},{"name":"email","enabled":false,"trial_expired":false},{"name":"duo","enabled":false,"trial_expired":false},{"name":"webauthn-roaming","enabled":false,"trial_expired":false},{"name":"webauthn-platform","enabled":false,"trial_expired":false},{"name":"recovery-code","enabled":false,"trial_expired":false}]'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down Expand Up @@ -51,7 +51,7 @@ interactions:
url: https://go-auth0-dev.eu.auth0.com/api/v2/guardian/factors
method: GET
response:
body: '[{"name":"sms","enabled":true,"trial_expired":false},{"name":"push-notification","enabled":false,"trial_expired":false},{"name":"otp","enabled":false,"trial_expired":false},{"name":"email","enabled":false,"trial_expired":false},{"name":"duo","enabled":true,"trial_expired":false},{"name":"webauthn-roaming","enabled":false,"trial_expired":false},{"name":"webauthn-platform","enabled":false,"trial_expired":false},{"name":"recovery-code","enabled":false,"trial_expired":false}]'
body: '[{"name":"sms","enabled":false,"trial_expired":false},{"name":"push-notification","enabled":false,"trial_expired":false},{"name":"otp","enabled":false,"trial_expired":false},{"name":"email","enabled":false,"trial_expired":false},{"name":"duo","enabled":true,"trial_expired":false},{"name":"webauthn-roaming","enabled":false,"trial_expired":false},{"name":"webauthn-platform","enabled":false,"trial_expired":false},{"name":"recovery-code","enabled":false,"trial_expired":false}]'
headers:
Content-Type:
- application/json; charset=utf-8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
version: 1
interactions:
- request:
body: |
null
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0-SDK/latest
url: https://go-auth0-dev.eu.auth0.com/api/v2/guardian/factors/duo/settings
method: GET
response:
body: '{"ikey":"asdasdasd","skey":"asdascxzcasd","host":"asdasdaasdas"}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 1ms
- request:
body: |
{"host":"api-hostname","ikey":"someKey","skey":"someSecret"}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0-SDK/latest
url: https://go-auth0-dev.eu.auth0.com/api/v2/guardian/factors/duo/settings
method: PUT
response:
body: '{"host":"api-hostname","ikey":"someKey","skey":"someSecret"}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 1ms
- request:
body: |
null
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0-SDK/latest
url: https://go-auth0-dev.eu.auth0.com/api/v2/guardian/factors/duo/settings
method: GET
response:
body: '{"ikey":"someKey","skey":"someSecret","host":"api-hostname"}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 1ms
- request:
body: |
{"host":"asdasdaasdas","ikey":"asdasdasd","skey":"asdascxzcasd"}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0-SDK/latest
url: https://go-auth0-dev.eu.auth0.com/api/v2/guardian/factors/duo/settings
method: PUT
response:
body: '{"host":"asdasdaasdas","ikey":"asdasdasd","skey":"asdascxzcasd"}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 1ms