Milan Pavlik d9ccc1d141
[papi] OIDC service signs state with HS256, reusing signing PK - WEB-206 (#17328)
* [papi] OIDC service signs state with RSA256

* Fix

* retest

* fix

* add test
2023-04-24 17:14:45 +08:00

33 lines
863 B
Go

// Copyright (c) 2023 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 oidc
import (
"testing"
"time"
"github.com/golang-jwt/jwt/v5"
"github.com/stretchr/testify/require"
)
func TestNewStateJWT(t *testing.T) {
var (
clientConfigID = "test-id"
returnURL = "test-url"
issuedAt = time.Now()
expiry = issuedAt.Add(5 * time.Minute)
)
token := NewStateJWT(clientConfigID, returnURL, issuedAt, expiry)
require.Equal(t, jwt.SigningMethodHS256, token.Method)
require.Equal(t, &StateClaims{
ClientConfigID: clientConfigID,
ReturnToURL: returnURL,
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(expiry),
IssuedAt: jwt.NewNumericDate(issuedAt),
},
}, token.Claims)
}