mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
34 lines
896 B
Go
34 lines
896 B
Go
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTokenToAndFromContext_AccessToken(t *testing.T) {
|
|
token := NewAccessToken("my_token")
|
|
|
|
extracted, err := TokenFromContext(TokenToContext(context.Background(), token))
|
|
require.NoError(t, err)
|
|
require.Equal(t, token, extracted)
|
|
}
|
|
|
|
func TestTokenToAndFromContext_CookieToken(t *testing.T) {
|
|
token := NewCookieToken("my_token")
|
|
|
|
extracted, err := TokenFromContext(TokenToContext(context.Background(), token))
|
|
require.NoError(t, err)
|
|
require.Equal(t, token, extracted)
|
|
}
|
|
|
|
func TestTokenFromContext_ErrorsWhenNotSet(t *testing.T) {
|
|
_, err := TokenFromContext(context.Background())
|
|
require.Error(t, err)
|
|
}
|