Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VC Jwts in tests are wrong #149

Open
nitro-neal opened this issue May 30, 2024 · 1 comment
Open

VC Jwts in tests are wrong #149

nitro-neal opened this issue May 30, 2024 · 1 comment

Comments

@nitro-neal
Copy link
Contributor

https://github.com/TBD54566975/web5-go/blob/main/vc/vcjwt_test.go

If we look at the "correct" test in the vcjst_test.go we see that this one passes:

{
  "exp": 2655213639,
  "iss": "did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6IlhBZjdfbV9rYkdlYUFqXzZoQ2pVTkNhTFRiQzNCcVdhNTZERHowbXpMUXMifQ",
  "jti": "abcd123",
  "nbf": 1709133639,
  "sub": "did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6ImtNRlVUU0ZZbkJDQVhFWUdGWjZ3Z3RTWVY3enQtcFNFZUtsN1NvaTNrX2MifQ",
  "vc": {
    "@context": [
      "https://www.w3.org/2018/credentials/v1"
    ],
    "type": [
      "VerifiableCredential"
    ],
    "issuer": "",
    "credentialSubject": {
      "firstName": "Randy",
      "lastName": "McRando"
    },
    "issuanceDate": ""
  }
}

However this should fail, "issuer": "", and "issuanceDate": "" should not be empty strings, but should either be the corresponding values to the iss and nbf, OR they should not exist at all.

I think some json flag needs to be turned on so if they are empty strings to just not produce them at all

@smaniotto
Copy link

Hi @nitro-neal, I was giving this one a try, but don't think the test case is wrong.

Here, the Decode function replaces issuanceDate with the nbf value, and issuer with the iss value from the JWT-specific properties (following the mentioned spec):
https://github.com/TBD54566975/web5-go/blob/24a79d937281dfdca1f66a1095eacfa16019b55c/vc/vcjwt.go#L64-L66
https://github.com/TBD54566975/web5-go/blob/24a79d937281dfdca1f66a1095eacfa16019b55c/vc/vcjwt.go#L80-L82
Actually, if we comment these lines out, we get the test to fail, since the DecodedVCJWT Verify method actually checks whether these fields are empty on the resulting vc field.

Maybe adding a test vector to cover this scenario will help with clarification:

{
	description: "jwt-specific properties replace vc model properties",
	input: "<jwt with empty properties to get replaced>",
	errors: false,
}, 

On a related note, since I was looking into this, these two sets of tests seem to have some overlapping:

  1. TestDecode and TestVector_Decode
  2. TestVerify and TestVector_Verify

Not sure if they're indeed duplicated (nor which would be the "correct" way that the project is following). Is it worth consolidating? I can send a PR, if it makes sense, wanted to grab an easy first issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants