mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
01b77384f9
Allow users to select and save the preferred duo device and method, depending on availability in the duo account. A default enrollment URL is provided and adjusted if returned by the duo API. This allows auto-enrollment if enabled by the administrator. Closes #594. Closes #1039.
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package suites
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/authelia/authelia/v4/internal/duo"
|
|
)
|
|
|
|
// DuoPolicy a type of policy.
|
|
type DuoPolicy int32
|
|
|
|
const (
|
|
// Deny deny policy.
|
|
Deny DuoPolicy = iota
|
|
// Allow allow policy.
|
|
Allow DuoPolicy = iota
|
|
)
|
|
|
|
// ConfigureDuo configure duo api to allow or block auth requests.
|
|
func ConfigureDuo(t *testing.T, allowDeny DuoPolicy) {
|
|
url := fmt.Sprintf("%s/allow", DuoBaseURL)
|
|
if allowDeny == Deny {
|
|
url = fmt.Sprintf("%s/deny", DuoBaseURL)
|
|
}
|
|
|
|
req, err := http.NewRequest("POST", url, nil)
|
|
require.NoError(t, err)
|
|
|
|
client := NewHTTPClient()
|
|
res, err := client.Do(req)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 200, res.StatusCode)
|
|
}
|
|
|
|
// ConfigureDuoPreAuth configure duo api to respond with available devices or enrollment Url.
|
|
func ConfigureDuoPreAuth(t *testing.T, response duo.PreAuthResponse) {
|
|
url := fmt.Sprintf("%s/preauth", DuoBaseURL)
|
|
|
|
body, err := json.Marshal(response)
|
|
require.NoError(t, err)
|
|
|
|
req, err := http.NewRequest("POST", url, bytes.NewReader(body))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
require.NoError(t, err)
|
|
|
|
client := NewHTTPClient()
|
|
res, err := client.Do(req)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 200, res.StatusCode)
|
|
}
|