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

ProofAttributeInfo.names should be an array type #47

Merged
merged 3 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}