-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improve handling of auth data in context (#262)
Signed-off-by: jannfis <[email protected]>
- Loading branch information
Showing
4 changed files
with
57 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package session | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_ClientIdFromContext(t *testing.T) { | ||
t.Run("Successfully extract client ID", func(t *testing.T) { | ||
ctx := ClientIdToContext(context.Background(), "agent") | ||
a, err := ClientIdFromContext(ctx) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "agent", a) | ||
}) | ||
t.Run("No client ID in context", func(t *testing.T) { | ||
a, err := ClientIdFromContext(context.Background()) | ||
assert.ErrorContains(t, err, "no client identifier") | ||
assert.Empty(t, a) | ||
}) | ||
t.Run("Invalid client ID in context", func(t *testing.T) { | ||
ctx := ClientIdToContext(context.Background(), "ag_ent") | ||
a, err := ClientIdFromContext(ctx) | ||
assert.ErrorContains(t, err, "invalid client identifier") | ||
assert.Empty(t, a) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters