Skip to content

Commit

Permalink
ProofAttributeInfo.names should be an array type (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
kukgini committed May 10, 2023
1 parent 6682c52 commit 224c438
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

import Foundation

public struct ProofAttributeInfo {
public let name: String?
public let names: String?
public let names: [String]?
public let nonRevoked: RevocationInterval?
public let restrictions: [AttributeFilter]?
}
Expand Down
70 changes: 69 additions & 1 deletion AriesFramework/AriesFrameworkTests/proofs/ProofsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class ProofsTest: XCTestCase {

let credentialPreview = CredentialPreview.fromDictionary([
"name": "John",
"sex": "Male",
"age": "99"
])

override func setUp() async throws {
try await super.setUp()

(faberAgent, aliceAgent, faberConnection, aliceConnection) = try await TestHelper.setupCredentialTests()
credDefId = try await TestHelper.prepareForIssuance(faberAgent, ["name", "age"])
credDefId = try await TestHelper.prepareForIssuance(faberAgent, ["name", "sex", "age"])
}

override func tearDown() async throws {
Expand Down Expand Up @@ -171,4 +172,71 @@ class ProofsTest: XCTestCase {
// Expected error
}
}

func getProofRequestWithMultipleAttributeNames() async throws -> ProofRequest {
let attributes = ["attrbutes1": ProofAttributeInfo(
name: nil, names: ["name", "sex"], nonRevoked: nil,
restrictions: [AttributeFilter(credentialDefinitionId: credDefId)])]
let predicates = ["age": ProofPredicateInfo(
name: "age", nonRevoked: nil, predicateType: .GreaterThanOrEqualTo, predicateValue: 50,
restrictions: [AttributeFilter(credentialDefinitionId: credDefId)])]

let nonce = try await ProofService.generateProofRequestNonce()
return ProofRequest(nonce: nonce, requestedAttributes: attributes, requestedPredicates: predicates)
}

func testProofRequestWithMultipleAttributeNames() async throws {
try await issueCredential()
let proofRequest = try await getProofRequestWithMultipleAttributeNames()
var faberProofRecord = try await faberAgent.proofs.requestProof(connectionId: faberConnection.id, proofRequest: proofRequest)
try await Task.sleep(nanoseconds: UInt64(0.1 * SECOND))

let threadId = faberProofRecord.threadId
var aliceProofRecord = try await getProofRecord(for: aliceAgent, threadId: threadId)
XCTAssertEqual(aliceProofRecord.state, .RequestReceived)

let retrievedCredentials = try await aliceAgent.proofs.getRequestedCredentialsForProofRequest(proofRecordId: aliceProofRecord.id)
let requestedCredentials = try await aliceAgent.proofService.autoSelectCredentialsForProofRequest(retrievedCredentials: retrievedCredentials)
aliceProofRecord = try await aliceAgent.proofs.acceptRequest(proofRecordId: aliceProofRecord.id, requestedCredentials: requestedCredentials)
try await Task.sleep(nanoseconds: UInt64(0.1 * SECOND))

faberProofRecord = try await getProofRecord(for: faberAgent, threadId: threadId)
XCTAssertEqual(faberProofRecord.state, .PresentationReceived)
XCTAssertEqual(faberProofRecord.isVerified, true)

faberProofRecord = try await faberAgent.proofs.acceptPresentation(proofRecordId: faberProofRecord.id)
try await Task.sleep(nanoseconds: UInt64(0.1 * SECOND))

aliceProofRecord = try await getProofRecord(for: aliceAgent, threadId: threadId)
XCTAssertEqual(aliceProofRecord.state, .Done)
XCTAssertEqual(faberProofRecord.state, .Done)
}

func getFailedProofRequestWithMultipleAttributeNames() async throws -> ProofRequest {
let attributes = ["attrbutes1": ProofAttributeInfo(
name: "name", names: ["name"], nonRevoked: nil,
restrictions: [AttributeFilter(credentialDefinitionId: credDefId)])]
let nonce = try await ProofService.generateProofRequestNonce()
return ProofRequest(nonce: nonce, requestedAttributes: attributes, requestedPredicates: [:])
}

func testProofWithFailingPredicates2() async throws {
try await issueCredential()
let proofRequest = try await getFailedProofRequestWithMultipleAttributeNames()
let faberProofRecord = try await faberAgent.proofs.requestProof(connectionId: faberConnection.id, proofRequest: proofRequest)

try await Task.sleep(nanoseconds: UInt64(0.1 * SECOND))

let threadId = faberProofRecord.threadId
let aliceProofRecord = try await getProofRecord(for: aliceAgent, threadId: threadId)

XCTAssertEqual(aliceProofRecord.state, .RequestReceived)

do {
let retrievedCredentials = try await aliceAgent.proofs.getRequestedCredentialsForProofRequest(proofRecordId: aliceProofRecord.id)
XCTFail("Error will raise because requested_attributes in the proof request has name and names both which is not allowed.")
} catch {
// Expected error
}
}
}

0 comments on commit 224c438

Please sign in to comment.