forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredential_jwt_test.go
55 lines (45 loc) · 1.4 KB
/
credential_jwt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package verifiable
import (
"errors"
"testing"
"time"
josejwt "github.com/square/go-jose/v3/jwt"
"github.com/stretchr/testify/require"
"github.com/hyperledger/aries-framework-go/pkg/doc/jwt"
)
func TestDecodeJWT(t *testing.T) {
vcBytes, err := decodeCredJWT("", func(string) (*JWTCredClaims, error) {
return nil, errors.New("cannot parse JWT claims")
})
require.Error(t, err)
require.Contains(t, err.Error(), "cannot parse JWT claims")
require.Nil(t, vcBytes)
}
func TestRefineVcFromJwtClaims(t *testing.T) {
issuerID := "did:example:76e12ec712ebc6f1c221ebfeb1f"
issued := time.Date(2019, time.August, 10, 0, 0, 0, 0, time.UTC)
vcID := "http://example.edu/credentials/3732"
expired := time.Date(2029, time.August, 10, 0, 0, 0, 0, time.UTC)
vcMap := map[string]interface{}{
"issuer": "unknown",
}
credClaims := &jwt.Claims{
Issuer: issuerID,
NotBefore: josejwt.NewNumericDate(issued),
ID: vcID,
IssuedAt: josejwt.NewNumericDate(issued),
Expiry: josejwt.NewNumericDate(expired),
}
jwtCredClaims := &JWTCredClaims{
Claims: credClaims,
VC: vcMap,
}
jwtCredClaims.refineFromJWTClaims()
require.Equal(t, issuerID, vcMap["issuer"])
require.Equal(t, "2019-08-10T00:00:00Z", vcMap["issuanceDate"])
require.Equal(t, "2029-08-10T00:00:00Z", vcMap["expirationDate"])
}