mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-21 23:53:14 +01:00
Validate authentik issuer url (#1723)
* Validate authentik issuer url * test issuer * adjust test times on windows
This commit is contained in:
parent
abd57d1191
commit
9b0fe2c8e5
@ -76,6 +76,10 @@ func NewAuthentikManager(config AuthentikClientConfig,
|
||||
return nil, fmt.Errorf("authentik IdP configuration is incomplete, TokenEndpoint is missing")
|
||||
}
|
||||
|
||||
if config.Issuer == "" {
|
||||
return nil, fmt.Errorf("authentik IdP configuration is incomplete, Issuer is missing")
|
||||
}
|
||||
|
||||
if config.GrantType == "" {
|
||||
return nil, fmt.Errorf("authentik IdP configuration is incomplete, GrantType is missing")
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/netbirdio/netbird/management/server/telemetry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/netbirdio/netbird/management/server/telemetry"
|
||||
)
|
||||
|
||||
func TestNewAuthentikManager(t *testing.T) {
|
||||
@ -25,6 +26,7 @@ func TestNewAuthentikManager(t *testing.T) {
|
||||
Username: "username",
|
||||
Password: "password",
|
||||
TokenEndpoint: "https://localhost:8080/application/o/token/",
|
||||
Issuer: "https://localhost:8080/application/o/netbird/",
|
||||
GrantType: "client_credentials",
|
||||
}
|
||||
|
||||
@ -75,7 +77,17 @@ func TestNewAuthentikManager(t *testing.T) {
|
||||
assertErrFuncMessage: "should return error when field empty",
|
||||
}
|
||||
|
||||
for _, testCase := range []test{testCase1, testCase2, testCase3, testCase4, testCase5} {
|
||||
testCase6Config := defaultTestConfig
|
||||
testCase6Config.Issuer = ""
|
||||
|
||||
testCase6 := test{
|
||||
name: "Missing Issuer Configuration",
|
||||
inputConfig: testCase6Config,
|
||||
assertErrFunc: require.Error,
|
||||
assertErrFuncMessage: "should return error when field empty",
|
||||
}
|
||||
|
||||
for _, testCase := range []test{testCase1, testCase2, testCase3, testCase4, testCase5, testCase6} {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
_, err := NewAuthentikManager(testCase.inputConfig, &telemetry.MockAppMetrics{})
|
||||
testCase.assertErrFunc(t, err, testCase.assertErrFuncMessage)
|
||||
|
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@ -25,7 +26,13 @@ func TestScheduler_Performance(t *testing.T) {
|
||||
return 0, false
|
||||
})
|
||||
}
|
||||
failed := waitTimeout(wg, 3*time.Second)
|
||||
timeout := 3 * time.Second
|
||||
if runtime.GOOS == "windows" {
|
||||
// sleep and ticker are slower on windows see https://github.com/golang/go/issues/44343
|
||||
timeout = 5 * time.Second
|
||||
}
|
||||
|
||||
failed := waitTimeout(wg, timeout)
|
||||
if failed {
|
||||
t.Fatal("timed out while waiting for test to finish")
|
||||
return
|
||||
@ -39,22 +46,29 @@ func TestScheduler_Cancel(t *testing.T) {
|
||||
scheduler := NewDefaultScheduler()
|
||||
tChan := make(chan struct{})
|
||||
p := []string{jobID1, jobID2}
|
||||
scheduler.Schedule(2*time.Millisecond, jobID1, func() (nextRunIn time.Duration, reschedule bool) {
|
||||
scheduletime := 2 * time.Millisecond
|
||||
sleepTime := 4 * time.Millisecond
|
||||
if runtime.GOOS == "windows" {
|
||||
// sleep and ticker are slower on windows see https://github.com/golang/go/issues/44343
|
||||
sleepTime = 20 * time.Millisecond
|
||||
}
|
||||
|
||||
scheduler.Schedule(scheduletime, jobID1, func() (nextRunIn time.Duration, reschedule bool) {
|
||||
tt := p[0]
|
||||
<-tChan
|
||||
t.Logf("job %s", tt)
|
||||
return 2 * time.Millisecond, true
|
||||
return scheduletime, true
|
||||
})
|
||||
scheduler.Schedule(2*time.Millisecond, jobID2, func() (nextRunIn time.Duration, reschedule bool) {
|
||||
return 2 * time.Millisecond, true
|
||||
scheduler.Schedule(scheduletime, jobID2, func() (nextRunIn time.Duration, reschedule bool) {
|
||||
return scheduletime, true
|
||||
})
|
||||
|
||||
time.Sleep(4 * time.Millisecond)
|
||||
time.Sleep(sleepTime)
|
||||
assert.Len(t, scheduler.jobs, 2)
|
||||
scheduler.Cancel([]string{jobID1})
|
||||
close(tChan)
|
||||
p = []string{}
|
||||
time.Sleep(4 * time.Millisecond)
|
||||
time.Sleep(sleepTime)
|
||||
assert.Len(t, scheduler.jobs, 1)
|
||||
assert.NotNil(t, scheduler.jobs[jobID2])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user