Skip to content

Commit

Permalink
[fix] added some tests for json represented sdjwts
Browse files Browse the repository at this point in the history
  • Loading branch information
dtsiflit committed Oct 2, 2024
1 parent 90b794e commit d78471e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{
"identity" : "jose-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/dtsiflit/jose-swift.git",
"location" : "https://github.com/beatt83/jose-swift.git",
"state" : {
"branch" : "fix/x509-chain-type",
"revision" : "7e5164025e89408398c415cff18dcb4e249d65f4"
"revision" : "c289a01f895501257e170d422a57a6edc593bbcd",
"version" : "4.0.0"
}
},
{
Expand Down
7 changes: 3 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let package = Package(
from: "5.0.1"
),
.package(
url: "https://github.com/dtsiflit/jose-swift.git",
branch: "fix/x509-chain-type"
url: "https://github.com/beatt83/jose-swift.git",
from: "4.0.0"
),
.package(
url: "https://github.com/apple/swift-certificates.git",
Expand All @@ -48,8 +48,7 @@ let package = Package(
dependencies: ["eudi-lib-sdjwt-swift"],
path: "Tests",
resources: [
// Process or copy resources in your test target
.process("Resources") // Specify the folder containing resources for tests
.process("Resources")
]
)
]
Expand Down
1 change: 1 addition & 0 deletions Sources/Parser/CompactParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class CompactParser: ParserProtocol {

var serialisedString: String
var serialisationFormat: SerialisationFormat = .serialised

// MARK: - Lifecycle

public required init(serialiserProtocol: SerialiserProtocol) {
Expand Down
59 changes: 53 additions & 6 deletions Tests/Verification/VcVerifierTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ final class VcVerifierTest: XCTestCase {
override func tearDown() async throws {
}

func testVerifyIssuance_WithValidSDJWT_ShouldSucceed() async throws {
func testVerifyIssuance_WithValidSDJWT_Withx509Header_ShouldSucceed() async throws {

// Given
let sdJwtString = SDJWTConstants.x509_sd_jwt.clean()

// When
let result = try await SDJWTVCVerifier(
fetcher: SdJwtVcIssuerMetaDataFetcher(
session: URLSession.shared
),
trust: X509CertificateChainVerifier()
)
.verifyIssuance(
Expand All @@ -51,7 +48,7 @@ final class VcVerifierTest: XCTestCase {
XCTAssertNoThrow(try result.get())
}

func testVerifyIssuance_WithIssuerMetaData_ShouldSucceed() async throws {
func testVerifyIssuance_WithValidSDJWT_WithIssuerMetaData_ShouldSucceed() async throws {

// Given
let sdJwtString = SDJWTConstants.issuer_metadata_sd_jwt.clean()
Expand All @@ -73,7 +70,7 @@ final class VcVerifierTest: XCTestCase {
XCTAssertNoThrow(try result.get())
}

func testVerifyIssuance_WithDID_ShouldSucceed() async throws {
func testVerifyIssuance_WithValidSDJWT_WithDID_ShouldSucceed() async throws {

// Given
let sdJwtString = SDJWTConstants.did_sd_jwt.clean()
Expand All @@ -89,4 +86,54 @@ final class VcVerifierTest: XCTestCase {
// Then
XCTAssertNoThrow(try result.get())
}

func testVerifyIssuance_WithValidSDJWTFlattendedJSON_Withx509Header_ShouldSucceed() async throws {

// Given
let sdJwtString = SDJWTConstants.x509_sd_jwt.clean()
let parser = CompactParser(serialisedString: sdJwtString)
let sdJwt = try! parser.getSignedSdJwt()

// When
let json = try sdJwt.asJwsJsonObject(
option: .flattened,
kbJwt: sdJwt.kbJwt?.compactSerialization,
getParts: parser.extractJWTParts
)

let result = try await SDJWTVCVerifier(
trust: X509CertificateChainVerifier()
)
.verifyIssuance(
unverifiedSdJwt: json
)

// Then
XCTAssertNoThrow(try result.get())
}

func testVerifyIssuance_WithValidSDJWTGeneralJSON_Withx509Header_ShouldSucceed() async throws {

// Given
let sdJwtString = SDJWTConstants.x509_sd_jwt.clean()
let parser = CompactParser(serialisedString: sdJwtString)
let sdJwt = try! parser.getSignedSdJwt()

// When
let json = try sdJwt.asJwsJsonObject(
option: .general,
kbJwt: sdJwt.kbJwt?.compactSerialization,
getParts: parser.extractJWTParts
)

let result = try await SDJWTVCVerifier(
trust: X509CertificateChainVerifier()
)
.verifyIssuance(
unverifiedSdJwt: json
)

// Then
XCTAssertNoThrow(try result.get())
}
}

0 comments on commit d78471e

Please sign in to comment.