Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 0938b22

Browse files
committed
Add more tests
1 parent 24d5dc1 commit 0938b22

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

internal/oidc/session_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestSessionStoreFactory(t *testing.T) {
7878
},
7979
}
8080

81-
store := &sessionStoreFactory{Config: config}
81+
store := NewSessionStoreFactory(config).(*sessionStoreFactory)
8282
g := run.Group{Logger: telemetry.NoopLogger()}
8383
g.Register(store)
8484
require.NoError(t, g.Run())
@@ -124,3 +124,21 @@ func TestSessionStoreFactoryRedisFails(t *testing.T) {
124124
mr.SetError("server error")
125125
require.ErrorContains(t, g.Run(), "server error")
126126
}
127+
128+
func TestSessionGenerator(t *testing.T) {
129+
t.Run("random", func(t *testing.T) {
130+
sg := NewRandomGenerator()
131+
require.NotEqual(t, sg.GenerateSessionID(), sg.GenerateSessionID())
132+
require.NotEqual(t, sg.GenerateState(), sg.GenerateState())
133+
require.NotEqual(t, sg.GenerateNonce(), sg.GenerateNonce())
134+
})
135+
t.Run("static", func(t *testing.T) {
136+
sg := NewStaticGenerator("sessionid", "nonce", "state")
137+
require.Equal(t, sg.GenerateSessionID(), sg.GenerateSessionID())
138+
require.Equal(t, sg.GenerateState(), sg.GenerateState())
139+
require.Equal(t, sg.GenerateNonce(), sg.GenerateNonce())
140+
require.Equal(t, "sessionid", sg.GenerateSessionID())
141+
require.Equal(t, "state", sg.GenerateState())
142+
require.Equal(t, "nonce", sg.GenerateNonce())
143+
})
144+
}

internal/server/requestid_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2024 Tetrate
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package server
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
envoy "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
22+
"github.com/stretchr/testify/require"
23+
"github.com/tetratelabs/telemetry"
24+
)
25+
26+
func TestPropagateRequestId(t *testing.T) {
27+
tests := []struct {
28+
name string
29+
req interface{}
30+
want []interface{}
31+
}{
32+
{"not-envoy-request", struct{}{}, nil},
33+
{"no-x-request-id", &envoy.CheckRequest{}, nil},
34+
{"with-x-request-id", header("test"), []interface{}{EnvoyXRequestID, "test-request-id"}},
35+
}
36+
37+
for _, tt := range tests {
38+
t.Run(tt.name, func(t *testing.T) {
39+
ctx := context.Background()
40+
_, _ = PropagateRequestID(ctx, tt.req, nil, func(ctx context.Context, req interface{}) (interface{}, error) {
41+
kvs := telemetry.KeyValuesFromContext(ctx)
42+
require.Equal(t, tt.want, kvs)
43+
return nil, nil
44+
})
45+
})
46+
}
47+
}

0 commit comments

Comments
 (0)