Skip to content

Commit

Permalink
Merge pull request #94 from velocitycareerlabs/VL-7981-proof
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
michaelavoyan authored Jun 4, 2024
2 parents 3ab49b7 + 457dee8 commit 96078a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class VCLFinalizeOffersDescriptor {
const proofJson: any = {};
if (proof) {
proofJson[VCLFinalizeOffersDescriptor.KeyProofType] = VCLFinalizeOffersDescriptor.KeyJwt;
proofJson[VCLFinalizeOffersDescriptor.KeyJwt] = proof.signedJwt.serialize();
proofJson[VCLFinalizeOffersDescriptor.KeyJwt] = proof.encodedJwt;
retVal[VCLFinalizeOffersDescriptor.KeyProof] = proofJson
}
return retVal;
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/api/entities/VCLJwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class VCLJwt {
}

get jwk(): Dictionary<any> {
return this.header.jwk || JSON.parse("{}")
return this.header.jwk || {}
}

get header(): Dictionary<any> {
Expand Down
50 changes: 25 additions & 25 deletions packages/sdk/test/entities/VCLJwt.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import VCLJwt from "../../src/api/entities/VCLJwt";
import "../../src/impl/extensions/StringExtensions";

let subject: VCLJwt
const jwtWtithKidStr =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InNvbWVfa2lkIn0.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.lGqyFj2RpmostxLvCcMFym9kWM0bzQcty9a81EdzrhM"
const jwtWtihJwkStr =
Expand All @@ -10,37 +9,38 @@ const jwtWtihJwkStr =
describe("test jwt", () => {

test("empty jwt", async () => {
subject = VCLJwt.fromEncodedJwt("")

expect(JSON.stringify(subject.header) == "{}").toBeTruthy()
expect(JSON.stringify(subject.payload) == "{}").toBeTruthy()
expect(subject.signature == "").toBeTruthy()
expect(subject.encodedJwt == "").toBeTruthy()
expect(JSON.stringify(subject.jwk) == "{}").toBeTruthy()
expect(subject.kid == "").toBeTruthy()
const subject = VCLJwt.fromEncodedJwt("")

expect(subject.header).toStrictEqual({})
expect(subject.payload).toStrictEqual({})
expect(subject.signature).toStrictEqual("")
expect(subject.encodedJwt).toStrictEqual("")
expect(subject.jwk).toStrictEqual({})
expect(subject.kid).toStrictEqual("")
})

test("valid jwt with kid", async () => {
subject = VCLJwt.fromEncodedJwt(jwtWtithKidStr)

expect(JSON.stringify(subject.header) == "{\"alg\":\"HS256\",\"typ\":\"JWT\",\"kid\":\"some_kid\"}").toBeTruthy()
expect(JSON.stringify(subject.payload) == "{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}").toBeTruthy()
expect(subject.signature == "lGqyFj2RpmostxLvCcMFym9kWM0bzQcty9a81EdzrhM").toBeTruthy()
expect(subject.encodedJwt == jwtWtithKidStr).toBeTruthy()
expect(JSON.stringify(subject.jwk) == "{}").toBeTruthy()
expect(subject.kid == "some_kid").toBeTruthy()
const subject = VCLJwt.fromEncodedJwt(jwtWtithKidStr)

expect(subject.header).toStrictEqual(JSON.parse("{\"alg\":\"HS256\",\"typ\":\"JWT\",\"kid\":\"some_kid\"}"))
expect(subject.payload).toStrictEqual(JSON.parse("{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}"))
expect(subject.signature).toStrictEqual("lGqyFj2RpmostxLvCcMFym9kWM0bzQcty9a81EdzrhM")
expect(subject.encodedJwt).toStrictEqual(jwtWtithKidStr)
expect(subject.jwk).toStrictEqual({})
expect(subject.kid).toStrictEqual("some_kid")
})

test("valid jwt with jwk", async () => {
subject = VCLJwt.fromEncodedJwt(jwtWtihJwkStr)
const subject = VCLJwt.fromEncodedJwt(jwtWtihJwkStr)

expect(JSON.stringify(subject.header) ==
expect(subject.header).toStrictEqual(
JSON.parse(
"{\"alg\":\"HS256\",\"typ\":\"JWT\",\"jwk\":{\"kty\":\"RSA\",\"use\":\"sig\",\"kid\":\"some_kid\",\"n\":\"zg7-8aYrxuV7H4t...\",\"e\":\"AQAB\"}}"
).toBeTruthy()
expect(JSON.stringify(subject.payload) == "{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}").toBeTruthy()
expect(subject.signature == "ijeuQTlhK7jpYkRmD_yWFKtluFWLEhjdieZJxkTc9fY").toBeTruthy()
expect(subject.encodedJwt == jwtWtihJwkStr).toBeTruthy()
expect(JSON.stringify(subject.jwk) == "{\"kty\":\"RSA\",\"use\":\"sig\",\"kid\":\"some_kid\",\"n\":\"zg7-8aYrxuV7H4t...\",\"e\":\"AQAB\"}").toBeTruthy()
expect(subject.kid == "some_kid").toBeTruthy()
))
expect(subject.payload).toStrictEqual(JSON.parse("{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}"))
expect(subject.signature).toStrictEqual("ijeuQTlhK7jpYkRmD_yWFKtluFWLEhjdieZJxkTc9fY")
expect(subject.encodedJwt).toStrictEqual(jwtWtihJwkStr)
expect(subject.jwk).toStrictEqual(JSON.parse("{\"kty\":\"RSA\",\"use\":\"sig\",\"kid\":\"some_kid\",\"n\":\"zg7-8aYrxuV7H4t...\",\"e\":\"AQAB\"}"))
expect(subject.kid).toStrictEqual("some_kid")
})
})

0 comments on commit 96078a0

Please sign in to comment.