mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 18:22:37 +02: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")
|
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 == "" {
|
if config.GrantType == "" {
|
||||||
return nil, fmt.Errorf("authentik IdP configuration is incomplete, GrantType is missing")
|
return nil, fmt.Errorf("authentik IdP configuration is incomplete, GrantType is missing")
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/telemetry"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/netbirdio/netbird/management/server/telemetry"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewAuthentikManager(t *testing.T) {
|
func TestNewAuthentikManager(t *testing.T) {
|
||||||
@ -25,6 +26,7 @@ func TestNewAuthentikManager(t *testing.T) {
|
|||||||
Username: "username",
|
Username: "username",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
TokenEndpoint: "https://localhost:8080/application/o/token/",
|
TokenEndpoint: "https://localhost:8080/application/o/token/",
|
||||||
|
Issuer: "https://localhost:8080/application/o/netbird/",
|
||||||
GrantType: "client_credentials",
|
GrantType: "client_credentials",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +77,17 @@ func TestNewAuthentikManager(t *testing.T) {
|
|||||||
assertErrFuncMessage: "should return error when field empty",
|
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) {
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
_, err := NewAuthentikManager(testCase.inputConfig, &telemetry.MockAppMetrics{})
|
_, err := NewAuthentikManager(testCase.inputConfig, &telemetry.MockAppMetrics{})
|
||||||
testCase.assertErrFunc(t, err, testCase.assertErrFuncMessage)
|
testCase.assertErrFunc(t, err, testCase.assertErrFuncMessage)
|
||||||
|
@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -25,7 +26,13 @@ func TestScheduler_Performance(t *testing.T) {
|
|||||||
return 0, false
|
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 {
|
if failed {
|
||||||
t.Fatal("timed out while waiting for test to finish")
|
t.Fatal("timed out while waiting for test to finish")
|
||||||
return
|
return
|
||||||
@ -39,22 +46,29 @@ func TestScheduler_Cancel(t *testing.T) {
|
|||||||
scheduler := NewDefaultScheduler()
|
scheduler := NewDefaultScheduler()
|
||||||
tChan := make(chan struct{})
|
tChan := make(chan struct{})
|
||||||
p := []string{jobID1, jobID2}
|
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]
|
tt := p[0]
|
||||||
<-tChan
|
<-tChan
|
||||||
t.Logf("job %s", tt)
|
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) {
|
scheduler.Schedule(scheduletime, jobID2, func() (nextRunIn time.Duration, reschedule bool) {
|
||||||
return 2 * time.Millisecond, true
|
return scheduletime, true
|
||||||
})
|
})
|
||||||
|
|
||||||
time.Sleep(4 * time.Millisecond)
|
time.Sleep(sleepTime)
|
||||||
assert.Len(t, scheduler.jobs, 2)
|
assert.Len(t, scheduler.jobs, 2)
|
||||||
scheduler.Cancel([]string{jobID1})
|
scheduler.Cancel([]string{jobID1})
|
||||||
close(tChan)
|
close(tChan)
|
||||||
p = []string{}
|
p = []string{}
|
||||||
time.Sleep(4 * time.Millisecond)
|
time.Sleep(sleepTime)
|
||||||
assert.Len(t, scheduler.jobs, 1)
|
assert.Len(t, scheduler.jobs, 1)
|
||||||
assert.NotNil(t, scheduler.jobs[jobID2])
|
assert.NotNil(t, scheduler.jobs[jobID2])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user