mirror of
https://github.com/goauthentik/authentik
synced 2026-04-27 09:57:31 +02:00
* packages/client-go: init Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove mod/sum Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix translate Signed-off-by: Jens Langhammer <jens@goauthentik.io> * no go replace Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update rust makefile with pwd Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix build Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't need a version ig? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * exclude go client from cspell Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix main docker build Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package flow_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"fmt"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/gorilla/securecookie"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/stretchr/testify/assert"
|
|
"goauthentik.io/internal/outpost/flow"
|
|
api "goauthentik.io/packages/client-go"
|
|
)
|
|
|
|
func testSecret() string {
|
|
return base64.RawURLEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
|
|
}
|
|
|
|
func TestFlowExecutor_SetSecrets_Plain(t *testing.T) {
|
|
fe := flow.NewFlowExecutor(context.TODO(), "", api.NewConfiguration(), logrus.Fields{})
|
|
pw := testSecret()
|
|
fe.SetSecrets(pw, false)
|
|
assert.Equal(t, pw, fe.Answers[flow.StagePassword])
|
|
assert.Equal(t, pw, fe.Answers[flow.StageAuthenticatorValidate])
|
|
}
|
|
|
|
func TestFlowExecutor_SetSecrets_TOTP_6(t *testing.T) {
|
|
fe := flow.NewFlowExecutor(context.TODO(), "", api.NewConfiguration(), logrus.Fields{})
|
|
pw := testSecret()
|
|
totp := 123456
|
|
formatted := fmt.Sprintf("%s%s%d", pw, flow.CodePasswordSeparator, totp)
|
|
fe.SetSecrets(formatted, true)
|
|
assert.Equal(t, pw, fe.Answers[flow.StagePassword])
|
|
assert.Equal(t, strconv.Itoa(totp), fe.Answers[flow.StageAuthenticatorValidate])
|
|
}
|
|
|
|
func TestFlowExecutor_SetSecrets_TOTP_8(t *testing.T) {
|
|
fe := flow.NewFlowExecutor(context.TODO(), "", api.NewConfiguration(), logrus.Fields{})
|
|
pw := testSecret()
|
|
totp := 12345678
|
|
formatted := fmt.Sprintf("%s%s%d", pw, flow.CodePasswordSeparator, totp)
|
|
fe.SetSecrets(formatted, true)
|
|
assert.Equal(t, pw, fe.Answers[flow.StagePassword])
|
|
assert.Equal(t, strconv.Itoa(totp), fe.Answers[flow.StageAuthenticatorValidate])
|
|
}
|
|
|
|
func TestFlowExecutor_SetSecrets_TOTP_TooLong(t *testing.T) {
|
|
fe := flow.NewFlowExecutor(context.TODO(), "", api.NewConfiguration(), logrus.Fields{})
|
|
pw := testSecret()
|
|
totp := 1234567890
|
|
formatted := fmt.Sprintf("%s%s%d", pw, flow.CodePasswordSeparator, totp)
|
|
fe.SetSecrets(formatted, true)
|
|
assert.Equal(t, formatted, fe.Answers[flow.StagePassword])
|
|
assert.Equal(t, "", fe.Answers[flow.StageAuthenticatorValidate])
|
|
}
|
|
|
|
func TestFlowExecutor_SetSecrets_TOTP_NoCode(t *testing.T) {
|
|
fe := flow.NewFlowExecutor(context.TODO(), "", api.NewConfiguration(), logrus.Fields{})
|
|
pw := testSecret()
|
|
fe.SetSecrets(pw, true)
|
|
assert.Equal(t, pw, fe.Answers[flow.StagePassword])
|
|
assert.Equal(t, "", fe.Answers[flow.StageAuthenticatorValidate])
|
|
fe.SetSecrets(pw+flow.CodePasswordSeparator, true)
|
|
assert.Equal(t, pw, fe.Answers[flow.StagePassword])
|
|
assert.Equal(t, "", fe.Answers[flow.StageAuthenticatorValidate])
|
|
}
|