Add Presentation network calls

This commit is contained in:
sydneymorton 2020-10-01 10:41:34 -07:00
Родитель e0715227c2
Коммит 1a77c93730
21 изменённых файлов: 318 добавлений и 18 удалений

Просмотреть файл

@ -7,6 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
5518CC642526427D00C7A21B /* PresentationResponseClaims.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC632526427D00C7A21B /* PresentationResponseClaims.swift */; };
5518CC68252645D000C7A21B /* PresentationSubmission.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC67252645D000C7A21B /* PresentationSubmission.swift */; };
5518CC6A2526469100C7A21B /* SubmissionDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC692526469100C7A21B /* SubmissionDescriptor.swift */; };
55575738251BC575009979AB /* VCEntities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5557572E251BC575009979AB /* VCEntities.framework */; };
5557573D251BC575009979AB /* VCEntitiesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5557573C251BC575009979AB /* VCEntitiesTests.swift */; };
5557573F251BC575009979AB /* VCEntities.h in Headers */ = {isa = PBXBuildFile; fileRef = 55575731251BC575009979AB /* VCEntities.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -65,6 +68,9 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
5518CC632526427D00C7A21B /* PresentationResponseClaims.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationResponseClaims.swift; sourceTree = "<group>"; };
5518CC67252645D000C7A21B /* PresentationSubmission.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationSubmission.swift; sourceTree = "<group>"; };
5518CC692526469100C7A21B /* SubmissionDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubmissionDescriptor.swift; sourceTree = "<group>"; };
5557572E251BC575009979AB /* VCEntities.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = VCEntities.framework; sourceTree = BUILT_PRODUCTS_DIR; };
55575731251BC575009979AB /* VCEntities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VCEntities.h; sourceTree = "<group>"; };
55575732251BC575009979AB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -135,6 +141,26 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
5518CC652526457500C7A21B /* claims */ = {
isa = PBXGroup;
children = (
5584E49A2525640000A9DE58 /* presentationExchangeRequest */,
5518CC662526458600C7A21B /* presentationExchangeResponse */,
5584E49825255ACA00A9DE58 /* PresentationRequestClaims.swift */,
5518CC632526427D00C7A21B /* PresentationResponseClaims.swift */,
);
path = claims;
sourceTree = "<group>";
};
5518CC662526458600C7A21B /* presentationExchangeResponse */ = {
isa = PBXGroup;
children = (
5518CC67252645D000C7A21B /* PresentationSubmission.swift */,
5518CC692526469100C7A21B /* SubmissionDescriptor.swift */,
);
path = presentationExchangeResponse;
sourceTree = "<group>";
};
55575724251BC575009979AB = {
isa = PBXGroup;
children = (
@ -163,6 +189,7 @@
5577E862251E8284005250BC /* issuance */,
557BFC50251E665D005B5B24 /* formatters */,
55575762251BC6CF009979AB /* JSONCodingKeys.swift */,
5557575A251BC6CF009979AB /* AttestationResponseDescriptor.swift */,
55575759251BC6CF009979AB /* OIDCClaims.swift */,
55575731251BC575009979AB /* VCEntities.h */,
55575732251BC575009979AB /* Info.plist */,
@ -221,7 +248,6 @@
isa = PBXGroup;
children = (
5557575F251BC6CF009979AB /* IssuanceResponseClaims.swift */,
5557575A251BC6CF009979AB /* AttestationResponseDescriptor.swift */,
55575760251BC6CF009979AB /* RegistrationClaims.swift */,
);
path = claims;
@ -292,13 +318,12 @@
5584E49725255A8F00A9DE58 /* presentation */ = {
isa = PBXGroup;
children = (
5584E49A2525640000A9DE58 /* presentationExchange */,
5584E49825255ACA00A9DE58 /* PresentationRequestClaims.swift */,
5518CC652526457500C7A21B /* claims */,
);
path = presentation;
sourceTree = "<group>";
};
5584E49A2525640000A9DE58 /* presentationExchange */ = {
5584E49A2525640000A9DE58 /* presentationExchangeRequest */ = {
isa = PBXGroup;
children = (
5584E49B2525641600A9DE58 /* PresentationDefinition.swift */,
@ -306,7 +331,7 @@
5584E49F2525656500A9DE58 /* SchemaDescriptor.swift */,
5584E4A1252565D900A9DE58 /* IssuanceMetadata.swift */,
);
path = presentationExchange;
path = presentationExchangeRequest;
sourceTree = "<group>";
};
92E29989252522C300B25BB6 /* Frameworks */ = {
@ -454,9 +479,12 @@
557BFC60251E6A6A005B5B24 /* IssuanceResponseFormatting.swift in Sources */,
5584E49C2525641600A9DE58 /* PresentationDefinition.swift in Sources */,
5584E4A2252565D900A9DE58 /* IssuanceMetadata.swift in Sources */,
5518CC68252645D000C7A21B /* PresentationSubmission.swift in Sources */,
5557576A251BC6CF009979AB /* Contract.swift in Sources */,
5557576D251BC6CF009979AB /* SelfIssuedClaimsDescriptor.swift in Sources */,
5518CC6A2526469100C7A21B /* SubmissionDescriptor.swift in Sources */,
5584E49E252564A600A9DE58 /* PresentationInputDescriptor.swift in Sources */,
5518CC642526427D00C7A21B /* PresentationResponseClaims.swift in Sources */,
55575775251BC6CF009979AB /* IssuanceResponseClaims.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

Просмотреть файл

@ -7,8 +7,6 @@ import VCJwt
public struct PresentationRequestClaims: OIDCClaims {
public let audience: String
public let clientID: String
public let issuer: String
@ -22,7 +20,6 @@ public struct PresentationRequestClaims: OIDCClaims {
public let presentationDefinition: PresentationDefinition
enum CodingKeys: String, CodingKey {
case audience = "aud"
case clientID = "client_id"
case issuer = "iss"
case presentationDefinition = "presentation_definition"

Просмотреть файл

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import VCJwt
public struct PresentationResponseClaims: OIDCClaims {
public let issuer: String = "https://self-issued.me"
public let publicKeyThumbprint: String
public let audience: String
public let did: String
public let publicJwk: ECPublicJwk?
public let contract: String
public let jti: String
public let presentationSubmission: PresentationSubmission?
public let attestations: AttestationResponseDescriptor?
public let iat: Double?
public let exp: Double?
public init(publicKeyThumbprint: String = "",
audience: String = "",
did: String = "",
publicJwk: ECPublicJwk? = nil,
contract: String = "",
jti: String = "",
attestations: AttestationResponseDescriptor? = nil,
presentationSubmission: PresentationSubmission? = nil,
iat: Double? = nil,
exp: Double? = nil) {
self.publicKeyThumbprint = publicKeyThumbprint
self.audience = audience
self.did = did
self.publicJwk = publicJwk
self.contract = contract
self.jti = jti
self.attestations = attestations
self.iat = iat
self.exp = exp
self.presentationSubmission = presentationSubmission
}
enum CodingKeys: String, CodingKey {
case issuer = "iss"
case publicKeyThumbprint = "sub"
case presentationSubmission = "presentation_submission"
case audience = "aud"
case publicJwk = "sub_jwk"
case contract, attestations, jti, did, iat, exp
}
}
public typealias PresentationResponse = JwsToken<PresentationResponseClaims>

Просмотреть файл

@ -5,9 +5,9 @@
public struct IssuanceMetadata: Codable {
public let contract: String
public let contract: String?
public let issuerDid: String
public let issuerDid: String?
enum CodingKeys: String, CodingKey {
case contract = "manifest"

Просмотреть файл

@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/
public struct SchemaDescriptor: Codable {
public let uri: String
public let uri: [String]?
public let name: String
public let name: String?
public let purpose: String
public let purpose: String?
}

Просмотреть файл

@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
public struct PresentationSubmission: Codable {
public let submissionDescriptors: [SubmissionDescriptor]
enum CodingKeys: String, CodingKey {
case submissionDescriptors = "descriptor_map"
}
}

Просмотреть файл

@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
public struct SubmissionDescriptor: Codable {
public let id: String
public let path: String
public let format: String
public let encoding: String
}

Просмотреть файл

@ -17,6 +17,9 @@
550F1D94250AEDBE009AF467 /* ContractDecoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1D93250AEDBE009AF467 /* ContractDecoderTests.swift */; };
550F1D9D250AFDF1009AF467 /* IssuanceResponseEncoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1D9C250AFDF1009AF467 /* IssuanceResponseEncoderTests.swift */; };
550F1DEC250D668D009AF467 /* PostNetworkOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1DEB250D668D009AF467 /* PostNetworkOperation.swift */; };
5518CC6C2526472000C7A21B /* PresentationResponseEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC6B2526472000C7A21B /* PresentationResponseEncoder.swift */; };
5518CC6E2526479900C7A21B /* PostPresentationResponseOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC6D2526479900C7A21B /* PostPresentationResponseOperation.swift */; };
5518CC702526483C00C7A21B /* PresentationServiceResponseDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC6F2526483C00C7A21B /* PresentationServiceResponseDecoder.swift */; };
5584E4A42526234C00A9DE58 /* FetchPresentationRequestOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5584E4A32526234C00A9DE58 /* FetchPresentationRequestOperation.swift */; };
5584E4A6252623EA00A9DE58 /* PresentationRequestDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5584E4A5252623EA00A9DE58 /* PresentationRequestDecoder.swift */; };
55C6C4A925083D370082BE73 /* Decoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55C6C4A825083D370082BE73 /* Decoding.swift */; };
@ -81,6 +84,9 @@
550F1D93250AEDBE009AF467 /* ContractDecoderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContractDecoderTests.swift; sourceTree = "<group>"; };
550F1D9C250AFDF1009AF467 /* IssuanceResponseEncoderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssuanceResponseEncoderTests.swift; sourceTree = "<group>"; };
550F1DEB250D668D009AF467 /* PostNetworkOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostNetworkOperation.swift; sourceTree = "<group>"; };
5518CC6B2526472000C7A21B /* PresentationResponseEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationResponseEncoder.swift; sourceTree = "<group>"; };
5518CC6D2526479900C7A21B /* PostPresentationResponseOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostPresentationResponseOperation.swift; sourceTree = "<group>"; };
5518CC6F2526483C00C7A21B /* PresentationServiceResponseDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationServiceResponseDecoder.swift; sourceTree = "<group>"; };
5584E4A32526234C00A9DE58 /* FetchPresentationRequestOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchPresentationRequestOperation.swift; sourceTree = "<group>"; };
5584E4A5252623EA00A9DE58 /* PresentationRequestDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationRequestDecoder.swift; sourceTree = "<group>"; };
55C6C4A825083D370082BE73 /* Decoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Decoding.swift; sourceTree = "<group>"; };
@ -161,6 +167,7 @@
children = (
550F1D6225094691009AF467 /* Encoding.swift */,
550F1D64250946CF009AF467 /* IssuanceResponseEncoder.swift */,
5518CC6B2526472000C7A21B /* PresentationResponseEncoder.swift */,
);
path = encoders;
sourceTree = "<group>";
@ -189,6 +196,7 @@
55C6C4AC250843920082BE73 /* ContractDecoder.swift */,
55C6C4AA250841000082BE73 /* IssuanceServiceResponseDecoder.swift */,
5584E4A5252623EA00A9DE58 /* PresentationRequestDecoder.swift */,
5518CC6F2526483C00C7A21B /* PresentationServiceResponseDecoder.swift */,
);
path = decoders;
sourceTree = "<group>";
@ -252,6 +260,7 @@
children = (
55D1680E24EB0E1C00AD2F98 /* PostIssuanceResponseOperation.swift */,
550F1DEB250D668D009AF467 /* PostNetworkOperation.swift */,
5518CC6D2526479900C7A21B /* PostPresentationResponseOperation.swift */,
);
path = post;
sourceTree = "<group>";
@ -555,16 +564,19 @@
5584E4A42526234C00A9DE58 /* FetchPresentationRequestOperation.swift in Sources */,
55D1681E24EB0E1D00AD2F98 /* NetworkOperation.swift in Sources */,
55D1681824EB0E1D00AD2F98 /* NetworkingError.swift in Sources */,
5518CC6E2526479900C7A21B /* PostPresentationResponseOperation.swift in Sources */,
922D7E6E252523FD00E4C8B5 /* NSObject+Promise.swift in Sources */,
55C6C4A925083D370082BE73 /* Decoding.swift in Sources */,
550F1DEC250D668D009AF467 /* PostNetworkOperation.swift in Sources */,
55D1682324EB0E1D00AD2F98 /* NetworkingConstants.swift in Sources */,
5584E4A6252623EA00A9DE58 /* PresentationRequestDecoder.swift in Sources */,
5518CC6C2526472000C7A21B /* PresentationResponseEncoder.swift in Sources */,
55D1682124EB0E1D00AD2F98 /* FailureHandler.swift in Sources */,
922D7E6A252523FD00E4C8B5 /* afterlife.swift in Sources */,
922D7E71252523FD00E4C8B5 /* Process+Promise.swift in Sources */,
922D7E6D252523FD00E4C8B5 /* NSURLSession+AnyPromise.m in Sources */,
55D1681924EB0E1D00AD2F98 /* HelperNetworkFunctions.swift in Sources */,
5518CC702526483C00C7A21B /* PresentationServiceResponseDecoder.swift in Sources */,
922D7E68252523FD00E4C8B5 /* NSNotificationCenter+Promise.swift in Sources */,
55C6C4AD250843920082BE73 /* ContractDecoder.swift in Sources */,
);

Просмотреть файл

@ -25,6 +25,8 @@
550F1E24250FC783009AF467 /* Fetching.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1E23250FC783009AF467 /* Fetching.swift */; };
550F1E26250FCA28009AF467 /* MockApiCalls.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1E25250FCA28009AF467 /* MockApiCalls.swift */; };
550F1E2A250FD7AB009AF467 /* ApiCalls.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1E29250FD7AB009AF467 /* ApiCalls.swift */; };
5518CC6025262CF700C7A21B /* PresentationRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC5F25262CF700C7A21B /* PresentationRepository.swift */; };
5518CC6225263C2E00C7A21B /* PresentationRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC6125263C2E00C7A21B /* PresentationRepositoryTests.swift */; };
92E7AA3425251AF2000E8246 /* VCNetworking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92E7AA3325251AF2000E8246 /* VCNetworking.framework */; };
92E7AA3825251B14000E8246 /* PromiseKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92E7AA3725251B14000E8246 /* PromiseKit.framework */; };
/* End PBXBuildFile section */
@ -61,6 +63,8 @@
550F1E23250FC783009AF467 /* Fetching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fetching.swift; sourceTree = "<group>"; };
550F1E25250FCA28009AF467 /* MockApiCalls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockApiCalls.swift; sourceTree = "<group>"; };
550F1E29250FD7AB009AF467 /* ApiCalls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiCalls.swift; sourceTree = "<group>"; };
5518CC5F25262CF700C7A21B /* PresentationRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationRepository.swift; sourceTree = "<group>"; };
5518CC6125263C2E00C7A21B /* PresentationRepositoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationRepositoryTests.swift; sourceTree = "<group>"; };
92E7AA3325251AF2000E8246 /* VCNetworking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = VCNetworking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
92E7AA3725251B14000E8246 /* PromiseKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = PromiseKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
92E7AA3A25251B1A000E8246 /* PMKFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = PMKFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -111,6 +115,7 @@
children = (
550F1E29250FD7AB009AF467 /* ApiCalls.swift */,
550F1DD0250BDA05009AF467 /* IssuanceRepository.swift */,
5518CC5F25262CF700C7A21B /* PresentationRepository.swift */,
550F1DD7250C0975009AF467 /* NetworkOperationFactory.swift */,
550F1DD9250C0997009AF467 /* NetworkOperationCreating.swift */,
550F1E23250FC783009AF467 /* Fetching.swift */,
@ -126,6 +131,7 @@
children = (
550F1DD2250BE851009AF467 /* mocks */,
550F1DE7250D5027009AF467 /* IssuanceRepositoryTests.swift */,
5518CC6125263C2E00C7A21B /* PresentationRepositoryTests.swift */,
550F1DE9250D599F009AF467 /* NetworkOperationFactoryTests.swift */,
550F1DC2250BD898009AF467 /* RepositoryTests.swift */,
550F1DC4250BD898009AF467 /* Info.plist */,
@ -270,6 +276,7 @@
550F1DDA250C0997009AF467 /* NetworkOperationCreating.swift in Sources */,
550F1E24250FC783009AF467 /* Fetching.swift in Sources */,
550F1DD1250BDA05009AF467 /* IssuanceRepository.swift in Sources */,
5518CC6025262CF700C7A21B /* PresentationRepository.swift in Sources */,
550F1DD8250C0975009AF467 /* NetworkOperationFactory.swift in Sources */,
550F1E2A250FD7AB009AF467 /* ApiCalls.swift in Sources */,
550F1E22250FC74E009AF467 /* Posting.swift in Sources */,
@ -285,6 +292,7 @@
550F1DC3250BD898009AF467 /* RepositoryTests.swift in Sources */,
550F1DF0250E7583009AF467 /* MockDecoder.swift in Sources */,
550F1DEA250D599F009AF467 /* NetworkOperationFactoryTests.swift in Sources */,
5518CC6225263C2E00C7A21B /* PresentationRepositoryTests.swift in Sources */,
550F1DEE250E753A009AF467 /* MockPostNetworkOperation.swift in Sources */,
550F1DE6250D4F73009AF467 /* MockRepository.swift in Sources */,
550F1DE2250D4964009AF467 /* MockNetworkOperation.swift in Sources */,

Просмотреть файл

@ -20,6 +20,8 @@ public class NetworkOperationFactory: NetworkOperationCreating {
switch type {
case is FetchContractOperation.Type:
seal.fulfill(try FetchContractOperation(withUrl: url) as! T)
case is FetchPresentationRequestOperation.Type:
seal.fulfill(try FetchPresentationRequestOperation(withUrl: url) as! T)
default:
seal.reject(RepositoryError.unsupportedNetworkOperation)
}
@ -30,7 +32,9 @@ public class NetworkOperationFactory: NetworkOperationCreating {
return Promise { seal in
switch type {
case is PostIssuanceResponseOperation.Type:
seal.fulfill(try PostIssuanceResponseOperation(withUrl: url, withBody: body as! IssuanceResponse) as! T)
seal.fulfill(try PostIssuanceResponseOperation(usingUrl: url, withBody: body as! IssuanceResponse) as! T)
case is PostPresentationResponseOperation.Type:
seal.fulfill(try PostPresentationResponseOperation(usingUrl: url, withBody: body as! PresentationResponse) as! T)
default:
seal.reject(RepositoryError.unsupportedNetworkOperation)
}

Просмотреть файл

@ -0,0 +1,25 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import VCNetworking
import PromiseKit
import VCEntities
public class PresentationRepository {
private let apiCalls: ApiCalling
public init(apiCalls: ApiCalling = ApiCalls()) {
self.apiCalls = apiCalls
}
public func getRequest(withUrl url: String) -> Promise<PresentationRequest> {
return self.apiCalls.get(FetchPresentationRequestOperation.self, usingUrl: url)
}
public func sendResponse(usingUrl url: String, withBody body: PresentationResponse) -> Promise<String?> {
return self.apiCalls.post(PostPresentationResponseOperation.self, usingUrl: url, withBody: body)
}
}

Просмотреть файл

@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import XCTest
import VCNetworking
import VCEntities
@testable import VCRepository
class PresentationRepositoryTests: XCTestCase {
var repo: PresentationRepository!
let expectedResult = "Result235"
let expectedUrl = "https://test352.com"
override func setUpWithError() throws {
let mockFactory = MockNetworkOperationFactory(result: expectedResult)
repo = PresentationRepository(apiCalls: MockApiCalls(factory: mockFactory))
}
func testGetCalled() {
let expec = self.expectation(description: "Fire")
repo.getRequest(withUrl: expectedUrl).done { actualResult in
XCTFail()
expec.fulfill()
}.catch { error in
XCTAssert(MockApiCalls.wasGetCalled)
XCTAssert(error is MockIssuanceRepoError)
expec.fulfill()
}
wait(for: [expec], timeout: 5)
}
func testReal() {
let url = "https://test-relyingparty.azurewebsites.net/request/jarIpvtW2FMJmA"
let expec = self.expectation(description: "Fire")
let repo = PresentationRepository()
repo.getRequest(withUrl: url).done { actualResult in
print(actualResult)
XCTFail()
expec.fulfill()
}.catch { error in
XCTAssert(MockApiCalls.wasGetCalled)
XCTAssert(error is MockIssuanceRepoError)
expec.fulfill()
}
wait(for: [expec], timeout: 5)
}
// func testPostCalled() {
// let expec = self.expectation(description: "Fire")
// let token = IssuanceResponse(from: TestData.issuanceResponse.rawValue)!
//
// repo.sendResponse(usingUrl: expectedUrl, withBody: token).done { actualResult in
// XCTFail()
// expec.fulfill()
// }.catch { error in
// XCTAssert(MockApiCalls.wasPostCalled)
// XCTAssert(error is MockIssuanceRepoError)
// expec.fulfill()
// }
//
// wait(for: [expec], timeout: 5)
// }
}

Просмотреть файл

@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import Foundation
public struct PresentationServiceResponseDecoder: Decoding {
public func decode(data: Data) throws -> String? {
return nil
}
}

Просмотреть файл

@ -16,5 +16,4 @@ struct IssuanceResponseEncoder: Encoding {
return encodedToken
}
}

Просмотреть файл

@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import Foundation
import VCEntities
struct PresentationResponseEncoder: Encoding {
func encode(value: PresentationResponse) throws -> Data {
guard let encodedToken = try value.serialize().data(using: .ascii) else {
throw NetworkingError.unableToParseString
}
return encodedToken
}
}

Просмотреть файл

@ -17,7 +17,7 @@ public class PostIssuanceResponseOperation: InternalPostNetworkOperation {
let urlSession: URLSession
let urlRequest: URLRequest
public init(withUrl urlStr: String, withBody body: IssuanceResponse, urlSession: URLSession = URLSession.shared) throws {
public init(usingUrl urlStr: String, withBody body: IssuanceResponse, urlSession: URLSession = URLSession.shared) throws {
guard let url = URL(string: urlStr) else {
throw NetworkingError.invalidUrl(withUrl: urlStr)

Просмотреть файл

@ -0,0 +1,34 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import Foundation
import VCEntities
public class PostPresentationResponseOperation: InternalPostNetworkOperation {
typealias Encoder = PresentationResponseEncoder
public typealias RequestBody = PresentationResponse
public typealias ResponseBody = String?
let decoder = PresentationServiceResponseDecoder()
let encoder = PresentationResponseEncoder()
let urlSession: URLSession
let urlRequest: URLRequest
public init(usingUrl urlStr: String, withBody body: PresentationResponse, urlSession: URLSession = URLSession.shared) throws {
guard let url = URL(string: urlStr) else {
throw NetworkingError.invalidUrl(withUrl: urlStr)
}
var request = URLRequest(url: url)
request.httpMethod = Constants.POST
request.httpBody = try self.encoder.encode(value: body)
request.setValue(Constants.PLAIN_TEXT, forHTTPHeaderField: Constants.CONTENT_TYPE)
self.urlRequest = request
self.urlSession = urlSession
}
}

Просмотреть файл

@ -23,7 +23,7 @@ class PostIssuanceResponseOperationTests: XCTestCase {
let configuration = URLSessionConfiguration.default
configuration.protocolClasses = [UrlProtocolMock.self]
let urlSession = URLSession.init(configuration: configuration)
postPresentationResponseOperation = try PostIssuanceResponseOperation(withUrl: self.expectedUrl, withBody: expectedRequestBody, urlSession: urlSession)
postPresentationResponseOperation = try PostIssuanceResponseOperation(usingUrl: self.expectedUrl, withBody: expectedRequestBody, urlSession: urlSession)
}
func testSuccessfulInit() throws {
@ -39,7 +39,7 @@ class PostIssuanceResponseOperationTests: XCTestCase {
func testInvalidUrlInit() {
let invalidUrl = ""
XCTAssertThrowsError(try PostIssuanceResponseOperation(withUrl: invalidUrl, withBody: expectedRequestBody)) { error in
XCTAssertThrowsError(try PostIssuanceResponseOperation(usingUrl: invalidUrl, withBody: expectedRequestBody)) { error in
XCTAssertEqual(error as! NetworkingError, NetworkingError.invalidUrl(withUrl: invalidUrl))
}
}