AuthN: Rebuild Authenticate so we only have to call it once in context handler (#61705)
* API: Add reqSignedIn to router groups * AuthN: Add fall through in context handler * AuthN: Add IsAnonymous field * AuthN: add priority to context aware clients * ContextHandler: Add comment * AuthN: Add a simple priority queue * AuthN: Add Name to client interface * AuthN: register clients with function * AuthN: update mock and fake to implement interface * AuthN: rewrite test without reflection * AuthN: add comment * AuthN: fix queue insert * AuthN: rewrite tests * AuthN: make the queue generic so we can reuse it for hooks * ContextHandler: Add fixme for auth headers * AuthN: remove unused variable * AuthN: use multierror * AuthN: write proper tests for queue * AuthN: Add queue item that can store the value and priority Co-authored-by: Jo <joao.guerreiro@grafana.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package authnimpl
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/authn/authntest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
)
|
||||
|
||||
func TestQueue(t *testing.T) {
|
||||
type testCase struct {
|
||||
desc string
|
||||
clients []authn.ContextAwareClient
|
||||
expectedOrder []string
|
||||
}
|
||||
|
||||
tests := []testCase{
|
||||
{
|
||||
desc: "expect correct order",
|
||||
clients: []authn.ContextAwareClient{
|
||||
&authntest.FakeClient{ExpectedName: "1", ExpectedPriority: 1},
|
||||
&authntest.FakeClient{ExpectedName: "5", ExpectedPriority: 5},
|
||||
&authntest.FakeClient{ExpectedName: "3", ExpectedPriority: 3},
|
||||
&authntest.FakeClient{ExpectedName: "2", ExpectedPriority: 2},
|
||||
&authntest.FakeClient{ExpectedName: "4", ExpectedPriority: 4},
|
||||
},
|
||||
expectedOrder: []string{"1", "2", "3", "4", "5"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
q := newQueue[authn.ContextAwareClient]()
|
||||
for _, c := range tt.clients {
|
||||
q.insert(c, c.Priority())
|
||||
}
|
||||
|
||||
require.Len(t, q.items, len(tt.expectedOrder))
|
||||
|
||||
for i := range q.items {
|
||||
assert.Equal(t, q.items[i].v.Name(), tt.expectedOrder[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user