From fd018f2a7a4a5774f468f1442e3edefc0c37b0e0 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Wed, 16 Aug 2017 17:53:55 +0300 Subject: [PATCH 01/29] iOS Wrapper: updated IndySignus class --- .../libindy-pod/libindy/Utils/IndyCallbacks.h | 20 ++++-- .../libindy/Utils/IndyCallbacks.mm | 48 ++++++++++++++ .../libindy-pod/libindy/Wrapper/IndySignus.h | 26 +++++--- .../libindy-pod/libindy/Wrapper/IndySignus.mm | 65 ++++++++++++------- 4 files changed, 123 insertions(+), 36 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.h b/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.h index ccfff2ce6e..c7f2a872aa 100644 --- a/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.h +++ b/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.h @@ -16,7 +16,7 @@ extern void IndyWrapperCommon3PHCallback(indy_handle_t xcommand_handle, extern void IndyWrapperCommon3PSCallback(indy_handle_t xcommand_handle, indy_error_t err, - const char* arg1); + const char *arg1); extern void IndyWrapperCommon3PBCallback(indy_handle_t xcommand_handle, indy_error_t err, @@ -24,21 +24,33 @@ extern void IndyWrapperCommon3PBCallback(indy_handle_t xcommand_handle, extern void IndyWrapperCommon4PCallback(indy_handle_t xcommand_handle, indy_error_t err, - const char* arg1, + const char *arg1, const char *arg2); +extern void IndyWrapperCommon4PDataCallback(indy_handle_t xcommand_handle, + indy_error_t err, + const uint8_t* arg1, + uint32_t arg2); + extern void IndyWrapperCommon5PCallback(indy_handle_t xcommand_handle, indy_error_t err, - const char* arg1, + const char *arg1, const char *arg2, const char *arg3); extern void IndyWrapperCommon5PSCallback(indy_handle_t xcommand_handle, indy_error_t err, indy_handle_t connection_handle, - const char* arg1, + const char *arg1, const char *arg2); +extern void IndyWrapperCommon6PDataCallback(indy_handle_t xcommand_handle, + indy_error_t err, + const uint8_t* arg1, + uint32_t arg2, + const uint8_t* arg3, + uint32_t arg4); + extern void IndyWrapperCommonAgentOutgoingConnectionCallback(indy_handle_t xcommand_handle, indy_error_t err, indy_handle_t connection_handle); diff --git a/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.mm b/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.mm index b2ebb944c6..8215a633f6 100644 --- a/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.mm +++ b/wrappers/ios/libindy-pod/libindy/Utils/IndyCallbacks.mm @@ -409,6 +409,29 @@ void IndyWrapperCommon4PCallback(indy_handle_t xcommand_handle, } } +/// Arguments arg1 and arg2 will be converted to nsdata +void IndyWrapperCommon4PDataCallback(indy_handle_t xcommand_handle, + indy_error_t err, + const uint8_t* arg1, + uint32_t arg2) +{ + void * block = [[IndyCallbacks sharedInstance] commandCompletionFor: xcommand_handle]; + [[IndyCallbacks sharedInstance] deleteCommandHandleFor: xcommand_handle]; + + void (^completion)(NSError*, NSData* arg) = (__bridge void (^)(NSError*, NSData* arg))block; + + NSData *sarg = [NSData dataWithBytes:arg1 length:arg2]; + + if (completion) + { + dispatch_async(dispatch_get_main_queue(), ^ + { + NSError *error = [ NSError errorFromIndyError: err ]; + completion(error, sarg); + }); + } +} + void IndyWrapperCommon5PCallback(indy_handle_t xcommand_handle, indy_error_t err, const char* arg1, @@ -458,6 +481,31 @@ void IndyWrapperCommon5PSCallback(indy_handle_t xcommand_handle, } } +void IndyWrapperCommon6PDataCallback(indy_handle_t xcommand_handle, + indy_error_t err, + const uint8_t* arg1, + uint32_t arg2, + const uint8_t* arg3, + uint32_t arg4) +{ + void * block = [[IndyCallbacks sharedInstance] commandCompletionFor: xcommand_handle]; + [[IndyCallbacks sharedInstance] deleteCommandHandleFor: xcommand_handle]; + + void (^completion)(NSError*, NSData* xArg1, NSData* xArg2) = (__bridge void (^)(NSError*, NSData* xArg1, NSData* xArg2))block; + + NSData *sarg1 = [NSData dataWithBytes:arg1 length:arg2]; + NSData *sarg2 = [NSData dataWithBytes:arg3 length:arg4]; + + if (completion) + { + dispatch_async(dispatch_get_main_queue(), ^ + { + NSError *error = [ NSError errorFromIndyError: err ]; + completion(error, sarg1, sarg2); + }); + } +} + void IndyWrapperCommonAgentOutgoingConnectionCallback(indy_handle_t xcommand_handle, indy_error_t err, indy_handle_t connection_handle) diff --git a/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.h b/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.h index 116872ae7a..cdffa0dd10 100644 --- a/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.h +++ b/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.h @@ -11,12 +11,17 @@ + (NSError *)createAndStoreMyDidWithWalletHandle:(IndyHandle)walletHandle didJSON:(NSString *)didJson - completion:(void (^)(NSError *error, NSString *did, NSString *verkey, NSString *pk)) handler; + completion:(void (^)(NSError *error, + NSString *did, + NSString *verkey, + NSString *pk)) handler; + (NSError *)replaceKeysWithWalletHandle:(IndyHandle)walletHandle did:(NSString *)did identityJSON:(NSString *)json - completion:(void (^)(NSError *error, NSString *verkey, NSString *pk)) handler; + completion:(void (^)(NSError *error, + NSString *verkey, + NSString *pk)) handler; + (NSError *)storeTheirDidWithWalletHandle:(IndyHandle)walletHandle identityJSON:(NSString *)json @@ -24,27 +29,28 @@ + (NSError *)signWithWalletHandle:(IndyHandle)walletHandle did:(NSString *)did - msg:(NSString *)msg - completion:(void (^)(NSError *error, NSString *signature)) handler; + message:(NSData*)message + completion:(void (^)(NSError *error, NSData *signature)) handler; + (NSError *)verifySignatureWithWalletHandle:(IndyHandle)walletHandle poolHandle:(IndyHandle)poolHandle did:(NSString *)did - signature:(NSString *)signature + message:(NSData *)message + signature:(NSData *)signature completion:(void (^)(NSError *error, BOOL valid)) handler; + (NSError *)encryptWithWalletHandle:(IndyHandle)walletHandle pool:(IndyHandle)poolHandle myDid:(NSString *)myDid did:(NSString *)did - msg:(NSString *)msg - completion:(void (^)(NSError *error, NSString *encryptedMsg, NSString *nonce)) handler; + message:(NSData *)message + completion:(void (^)(NSError *error, NSData *encryptedMsg, NSData *nonce)) handler; + (NSError *)decryptWithWalletHandle:(IndyHandle)walletHandle myDid:(NSString *)myDid did:(NSString *)did - encryptedMsg:(NSString *)msg - nonce:(NSString *)nonce - completion:(void (^)(NSError *error, NSString *decryptedMsg)) handler; + encryptedMessage:(NSData *)encryptedMessage + nonce:(NSData *)nonce + completion:(void (^)(NSError *error, NSData *decryptedMessage)) handler; @end diff --git a/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.mm b/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.mm index 47dd938d71..d203abc233 100644 --- a/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.mm +++ b/wrappers/ios/libindy-pod/libindy/Wrapper/IndySignus.mm @@ -77,19 +77,22 @@ + (NSError *)storeTheirDidWithWalletHandle:(IndyHandle)walletHandle + (NSError *)signWithWalletHandle:(IndyHandle)walletHandle did:(NSString *)did - msg:(NSString *)msg - completion:(void (^)(NSError *error, NSString *signature)) handler + message:(NSData*)message + completion:(void (^)(NSError *error, + NSData *signature)) handler { indy_error_t ret; indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor: (void*) handler]; - ret = indy_sign( handle, + uint32_t messageLen = (uint32_t)[message length]; + uint8_t *messageRaw = (uint8_t *)[message bytes]; + ret = indy_sign(handle, walletHandle, [did UTF8String], - [msg UTF8String], - IndyWrapperCommon3PSCallback - ); + messageRaw, + messageLen, + IndyWrapperCommon4PDataCallback); if( ret != Success ) { @@ -102,18 +105,27 @@ + (NSError *)signWithWalletHandle:(IndyHandle)walletHandle + (NSError *)verifySignatureWithWalletHandle:(IndyHandle)walletHandle poolHandle:(IndyHandle)poolHandle did:(NSString *)did - signature:(NSString *)signature + message:(NSData *)message + signature:(NSData *)signature completion:(void (^)(NSError *error, BOOL valid)) handler { indy_error_t ret; indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor: (void*) handler]; + uint32_t messageLen = (uint32_t)[message length]; + uint8_t *messageRaw = (uint8_t *)[message bytes]; + uint32_t signatureLen = (uint32_t)[signature length]; + uint8_t *signatureRaw = (uint8_t *)[signature bytes]; + ret = indy_verify_signature(handle, walletHandle, poolHandle, [did UTF8String], - [signature UTF8String], + messageRaw, + messageLen, + signatureRaw, + signatureLen, IndyWrapperCommon3PBCallback); if( ret != Success ) { @@ -127,21 +139,24 @@ + (NSError *)encryptWithWalletHandle:(IndyHandle)walletHandle pool:(IndyHandle)poolHandle myDid:(NSString *)myDid did:(NSString *)did - msg:(NSString *)msg - completion:(void (^)(NSError *error, NSString *encryptedMsg, NSString *nonce)) handler + message:(NSData *)message + completion:(void (^)(NSError *error, NSData *encryptedMsg, NSData *nonce)) handler { indy_error_t ret; indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor: (void*) handler]; - ret = indy_encrypt( handle, + uint32_t messageLen = (uint32_t)[message length]; + uint8_t *messageRaw = (uint8_t *)[message bytes]; + + ret = indy_encrypt(handle, walletHandle, poolHandle, [myDid UTF8String], [did UTF8String], - [msg UTF8String], - IndyWrapperCommon4PCallback - ); + messageRaw, + messageLen, + IndyWrapperCommon6PDataCallback); if( ret != Success ) { @@ -154,22 +169,28 @@ + (NSError *)encryptWithWalletHandle:(IndyHandle)walletHandle + (NSError *)decryptWithWalletHandle:(IndyHandle)walletHandle myDid:(NSString *)myDid did:(NSString *)did - encryptedMsg:(NSString *)msg - nonce:(NSString *)nonce - completion:(void (^)(NSError *error, NSString *decryptedMsg)) handler + encryptedMessage:(NSData *)encryptedMessage + nonce:(NSData *)nonce + completion:(void (^)(NSError *error, NSData *decryptedMessage)) handler { indy_error_t ret; indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor: (void*) handler]; - ret = indy_decrypt( handle, + uint32_t messageLen = (uint32_t)[encryptedMessage length]; + uint8_t *messageRaw = (uint8_t *)[encryptedMessage bytes]; + uint32_t nonceLen = (uint32_t)[nonce length]; + uint8_t *nonceRaw = (uint8_t *)[nonce bytes]; + + ret = indy_decrypt(handle, walletHandle, [myDid UTF8String], [did UTF8String], - [msg UTF8String], - [nonce UTF8String], - IndyWrapperCommon3PSCallback - ); + messageRaw, + messageLen, + nonceRaw, + nonceLen, + IndyWrapperCommon4PDataCallback); if( ret != Success ) { From 05e924c23af94730e4631a1ecb8ac6036e3133d9 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Wed, 16 Aug 2017 18:21:37 +0300 Subject: [PATCH 02/29] iOS: Updated SignusUtils --- .../Test Utils/SignusUtils.h | 7 +-- .../Test Utils/SignusUtils.mm | 51 +++++++++---------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h index 8862ace447..851081e28e 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h @@ -16,8 +16,8 @@ - (NSError *)signWithWalletHandle:(IndyHandle)walletHandle theirDid:(NSString *)theirDid - message:(NSString *)message - outSignature:(NSString **)signature; + message:(NSData *)message + outSignature:(NSData **)signature; - (NSError *)createMyDidWithWalletHandle:(IndyHandle)walletHandle myDidJson:(NSString *)myDidJson @@ -49,6 +49,7 @@ - (NSError *)verifyWithWalletHandle:(IndyHandle)walletHandle poolHandle:(IndyHandle)poolHandle did:(NSString *)did - signature:(NSString *)signature + message:(NSData *)message + signature:(NSData *)signature outVerified:(BOOL *)verified; @end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm index 868f4f06df..66c58b339f 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm @@ -26,24 +26,24 @@ + (SignusUtils *)sharedInstance } - (NSError *)signWithWalletHandle:(IndyHandle)walletHandle theirDid:(NSString *)theirDid - message:(NSString *)message - outSignature:(NSString **)signature + message:(NSData *)message + outSignature:(NSData **)signature { XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; __block NSError *err = nil; - __block NSString *signSignature = nil; NSError *ret; - + ret = [IndySignus signWithWalletHandle:walletHandle - did:theirDid - msg:message - completion:^(NSError *error, NSString *blockSignature) - { - err = error; - signSignature = blockSignature; - [completionExpectation fulfill]; - }]; + did:theirDid + message:message + completion:^(NSError *error, NSData *blockSignature) + { + err = error; + if (signature) { *signature = blockSignature; } + [completionExpectation fulfill]; + }]; + if( ret.code != Success) { @@ -52,8 +52,6 @@ - (NSError *)signWithWalletHandle:(IndyHandle)walletHandle [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - if (signature) { *signature = signSignature; } - return err; } @@ -239,24 +237,25 @@ - (NSError *)replaceKeysWithWalletHandle:(IndyHandle)walletHandle - (NSError *)verifyWithWalletHandle:(IndyHandle)walletHandle poolHandle:(IndyHandle)poolHandle did:(NSString *)did - signature:(NSString *)signature + message:(NSData *)message + signature:(NSData *)signature outVerified:(BOOL *)verified { XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; __block NSError *err = nil; - __block BOOL outVerified; NSError *ret; ret = [IndySignus verifySignatureWithWalletHandle:walletHandle - poolHandle:poolHandle - did:did - signature:signature - completion:^(NSError *error, BOOL valid) - { - err = error; - outVerified = valid; - [completionExpectation fulfill]; - }]; + poolHandle:poolHandle + did:did + message:message + signature:signature + completion:^(NSError *error, BOOL valid) + { + err = error; + if (verified) { *verified = valid; } + [completionExpectation fulfill]; + }]; if( ret.code != Success) { @@ -265,8 +264,6 @@ - (NSError *)verifyWithWalletHandle:(IndyHandle)walletHandle [self waitForExpectations: @[completionExpectation] timeout:[TestUtils longTimeout]]; - if (verified) { *verified = outVerified; } - return err; } From 66d6ce4005dad37fd8e643679fe0be1070293488 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 11:03:28 +0300 Subject: [PATCH 03/29] iOS: Updated signus high cases tests for sign and verify --- .../Case Tests/Signus/SignusHighCases.m | 156 ++++++++---------- .../Test Utils/SignusUtils.h | 12 ++ .../Test Utils/SignusUtils.mm | 39 +++++ 3 files changed, 117 insertions(+), 90 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m index 77284fc067..ba043c59a3 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m @@ -362,14 +362,14 @@ - (void)testSignWorks // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[SignusUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); // 2. create my did NSString *myDid; - NSString *myDidJson = @"{\"seed\":\"000000000000000000000000Trustee1\"}"; + NSString *myDidJson = [NSString stringWithFormat:@"{\"seed\":\"%@\"}",[SignusUtils mySeed]]; ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle myDidJson:myDidJson outMyDid:&myDid @@ -378,51 +378,36 @@ - (void)testSignWorks XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed"); // 3. Sign - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\","\ - "\"operation\":{"\ - "\"type\":\"1\","\ - "\"dest\":\"VsKV7grR1BUE29mG2Fm2kX\","\ - "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\""\ - "}}"; - - NSMutableDictionary *expectedSignature = [NSMutableDictionary new]; - expectedSignature[@"signature"] = @"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW"; - - NSString *signatureJson; - ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle - theirDid:myDid message:message - outSignature:&signatureJson]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::signWithWalletHandle() failed"); - NSDictionary *signature = [NSDictionary fromString:signatureJson]; - XCTAssertTrue([signature contains:expectedSignature]); + NSData *signature; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle + theirDid:myDid + message:message + outSignature:&signature]; + XCTAssertTrue([signature isEqualToData:[SignusUtils signature]], @"SignusUtils::signWithWalletHandle() failed. Signature is not verified"); [TestUtils cleanupStorage]; } -- (void)testSignWorksForUnknownDid +- (void)testSignWorksForUnknownSigner { [TestUtils cleanupStorage]; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[SignusUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); - // 2. Sign - NSString *message = @"{"\ - "\"reqId\":1495034346617224651}"; - - NSString *signatureJson; + NSData *signature; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle - theirDid:@"some_did" + theirDid:@"did" message:message - outSignature:&signatureJson]; + outSignature:&signature]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::signWithWalletHandle() returned wrong error"); [TestUtils cleanupStorage]; @@ -435,33 +420,32 @@ - (void)testSignWorksForInvalidWalletHandle // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[SignusUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); // 2. create my did NSString *myDid; - NSString *myDidJson = @"{\"seed\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"; ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle - myDidJson:myDidJson + myDidJson:@"{}" outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed"); // 3. Sign - NSString *message = @"{"\ - "\"reqId\":1495034346617224651}"; - - NSString *signatureJson; + NSData *signature; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; IndyHandle invalidWalletHandle = walletHandle + 1; ret = [[SignusUtils sharedInstance] signWithWalletHandle:invalidWalletHandle theirDid:myDid message:message - outSignature:&signatureJson]; + outSignature:&signature]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::signWithWalletHandle() returned wrong code"); + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; } @@ -471,7 +455,7 @@ - (void)testVerifyWorksForVerkeyCachedInWallet { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_verkey_cached_in_wallet"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -492,7 +476,7 @@ - (void)testVerifyWorksForVerkeyCachedInWallet NSString *did; NSString *verKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:@"000000000000000000000000Trustee1" + seed:[SignusUtils mySeed] outMyDid:&did outMyVerkey:&verKey outMyPk:nil]; @@ -507,25 +491,20 @@ - (void)testVerifyWorksForVerkeyCachedInWallet XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); // 5. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\","\ - "\"operation\":{"\ - "\"type\":\"1\","\ - "\"dest\":\"VsKV7grR1BUE29mG2Fm2kX\","\ - "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\""\ - "},"\ - "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\"}"; - + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; BOOL verified = NO; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:did - signature:message + message:message + signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified, @"verifying failed"); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; } @@ -533,7 +512,7 @@ - (void)testVerifyWorksForGetVerkeyFromLedger { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_get_verkey_from_ledger"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -553,7 +532,7 @@ - (void)testVerifyWorksForGetVerkeyFromLedger // 3. trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:@"000000000000000000000000Trustee1" + seed:[SignusUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -564,7 +543,7 @@ - (void)testVerifyWorksForGetVerkeyFromLedger NSString *myDid; NSString *myVerKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:@"00000000000000000000000000000My1" + seed:[SignusUtils mySeed] outMyDid:&myDid outMyVerkey:&myVerKey outMyPk:nil]; @@ -591,9 +570,6 @@ - (void)testVerifyWorksForGetVerkeyFromLedger XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed"); // 7. Store their did - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\"}",myDid]; ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; @@ -601,14 +577,19 @@ - (void)testVerifyWorksForGetVerkeyFromLedger // 8. Verify BOOL verified = NO; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - signature:message + message:message + signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified, @"verifying failed"); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; } @@ -616,7 +597,7 @@ - (void)testVerifyWorksForExpiredNym { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_expired_nym"; + NSString *poolName = [SignusUtils pool]; NSString *walletName = @"wallet1"; // 1. Create and open pool ledger config, get pool handle @@ -644,7 +625,7 @@ - (void)testVerifyWorksForExpiredNym // 4. trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:@"000000000000000000000000Trustee1" + seed:[SignusUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -655,7 +636,7 @@ - (void)testVerifyWorksForExpiredNym NSString *myDid; NSString *myVerKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:@"00000000000000000000000000000My1" + seed:[SignusUtils mySeed] outMyDid:&myDid outMyVerkey:&myVerKey outMyPk:nil]; @@ -688,19 +669,20 @@ - (void)testVerifyWorksForExpiredNym XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); // 8. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; - BOOL verified = NO; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - signature:message + message:message + signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified, @"verifying failed"); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; } @@ -709,7 +691,7 @@ - (void)testVerifyWorksForInvalidWalletHandle { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_invalid_wallet_handle"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -728,25 +710,20 @@ - (void)testVerifyWorksForInvalidWalletHandle // 3. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"identifier\":GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL,"\ - "\"operation\":{"\ - "\"type\":\"1\","\ - "\"dest\":\"VsKV7grR1BUE29mG2Fm2kX\","\ - "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"},"\ - "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\"}"; - - // 4. Verify BOOL verified = NO; + NSData * message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; IndyHandle invalidWalletHandle = walletHandle + 1; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:invalidWalletHandle poolHandle:poolHandle did:@"did" - signature:message + message:message + signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::verifyWithWalletHandle() failed"); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; } @@ -754,7 +731,7 @@ - (void)testVerifyWorksForInvalidPoolHandle { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_invalid_pool_handle"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -772,28 +749,27 @@ - (void)testVerifyWorksForInvalidPoolHandle XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); // 3. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\","\ - "\"operation\":{"\ - "\"type\":\"1\","\ - "\"dest\":\"VsKV7grR1BUE29mG2Fm2kX\","\ - "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"},"\ - "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\"}"; - - // 4. Verify BOOL verified = NO; + NSData * message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; IndyHandle invalidPoolHandle = poolHandle + 1; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:invalidPoolHandle did:@"did" - signature:message + message:message + signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, PoolLedgerInvalidPoolHandle, @"SignusUtils::verifyWithWalletHandle() failed"); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; } +// MARK: - Encrypt + +// MARK: - Decrypt + @end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h index 851081e28e..3dc9f658db 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h @@ -14,6 +14,18 @@ + (SignusUtils *)sharedInstance; +// MARK: - Class variables + ++ (NSString *)pool; ++ (NSString *)message; ++ (NSData *)encryptedMessage; ++ (NSData *)nonce; ++ (NSData *)signature; ++ (NSString *)trusteeSeed; ++ (NSString *)mySeed; + +// MARK: - Instance methods + - (NSError *)signWithWalletHandle:(IndyHandle)walletHandle theirDid:(NSString *)theirDid message:(NSData *)message diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm index 66c58b339f..ad3db0ac93 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm @@ -24,6 +24,45 @@ + (SignusUtils *)sharedInstance return instance; } + ++ (NSString *)pool +{ + return @"pool_1"; +} + ++ (NSString *)message +{ + return @"{\"reqId\":1496822211362017764}"; +} + ++ (NSData *)encryptedMessage +{ + const unsigned char bytes[] = {242, 246, 53, 153, 106, 37, 185, 65, 212, 14, 109, 131, 200, 169, 94, 110, 51, 47, 101, 89, 0, 171, 105, 183}; + return [NSData dataWithBytes:bytes length:sizeof(bytes)]; +} + ++ (NSData *)nonce +{ + const unsigned char bytes[] = {187, 227, 10, 29, 46, 178, 12, 179, 197, 69, 171, 70, 228, 204, 52, 22, 199, 54, 62, 13, 115, 5, 216, 66, 20, 131, 121, 29, 251, 224, 253, 201, 75, 73, 225, 237, 219, 133, 35, 217, 131, 135, 232, 129, 32}; + return [NSData dataWithBytes:bytes length:sizeof(bytes)]; +} + ++ (NSData *)signature +{ + const unsigned char bytes[] = {169, 215, 8, 225, 7, 107, 110, 9, 193, 162, 202, 214, 162, 66, 238, 211, 63, 209, 12, 196, 8, 211, 55, 27, 120, 94, 204, 147, 53, 104, 103, 61, 60, 249, 237, 127, 103, 46, 220, 223, 10, 95, 75, 53, 245, 210, 241, 151, 191, 41, 48, 30, 9, 16, 78, 252, 157, 206, 210, 145, 125, 133, 109, 11}; + return [NSData dataWithBytes:bytes length:sizeof(bytes)]; +} + ++ (NSString *)trusteeSeed +{ + return @"000000000000000000000000"; +} + ++ (NSString *)mySeed +{ + return @"00000000000000000000000000000"; +} + - (NSError *)signWithWalletHandle:(IndyHandle)walletHandle theirDid:(NSString *)theirDid message:(NSData *)message From a23f85609d9d2d76ab6b682be03048f8b4086e5a Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 11:20:04 +0300 Subject: [PATCH 04/29] iOS: Added encrypt and decrypt method to SignusUtils --- .../Case Tests/Signus/SignusHighCases.m | 58 ++++++++++++++++ .../Test Utils/SignusUtils.mm | 69 +++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m index ba043c59a3..fb8beaa151 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m @@ -768,6 +768,64 @@ - (void)testVerifyWorksForInvalidPoolHandle // MARK: - Encrypt +- (void)testEncryptWorksForPubKeyCachedInWallet +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. trustee did + NSString *trusteeDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&trusteeDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + XCTAssertTrue(trusteeDid, @"invalid did"); + + // 4. my did + NSString *myDid; + NSString *myVerKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:&myVerKey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(myDid, @"invalid did"); + XCTAssertTrue(myVerKey, @"invalid verkey"); + + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",myDid, myVerKey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 6. encrypt + + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + // MARK: - Decrypt diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm index ad3db0ac93..8c8d00fdb8 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm @@ -306,4 +306,73 @@ - (NSError *)verifyWithWalletHandle:(IndyHandle)walletHandle return err; } +- (NSError *)encryptWithWalletHandle:(IndyHandle)walletHandle + poolHandle:(IndyHandle)poolHandle + myDid:(NSString *)myDid + did:(NSString *)did + message:(NSData *)message + outEncryptedMessage:(NSData **)encryptedMessage + outNonce:(NSData **)nonce +{ + XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + __block NSError *err = nil; + NSError *ret; + + ret = [IndySignus encryptWithWalletHandle:walletHandle + pool:poolHandle + myDid:myDid + did:did + message:message + completion:^(NSError *error, NSData *encryptedMsg, NSData *closureNonce) + { + err = error; + if (encryptedMessage) { *encryptedMessage = encryptedMsg; } + if (nonce) { *nonce = closureNonce; } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils longTimeout]]; + + return err; +} + +- (NSError *)decryptWithWalletHandle:(IndyHandle)walletHandle + myDid:(NSString *)myDid + did:(NSString *)did + encryptedMessage:(NSData *)encryptedMessage + nonce:(NSData *)nonce + outDecryptedMessage:(NSData **)decryptedMessage +{ + XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + __block NSError *err = nil; + NSError *ret; + + ret = [IndySignus decryptWithWalletHandle:walletHandle + myDid:myDid + did:did + encryptedMessage:encryptedMessage + nonce:nonce + completion:^(NSError *error, NSData *decryptedMsg) + { + err = error; + if (decryptedMessage) { *decryptedMessage = decryptedMsg; } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils longTimeout]]; + + return err; +} + + @end From c1e5446085cf634fc688f3c52cc851482d3168a7 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 11:46:16 +0300 Subject: [PATCH 05/29] iOS: Added signus high cases tests for encrypt --- .../Case Tests/Signus/SignusHighCases.m | 352 +++++++++++++++++- .../Test Utils/SignusUtils.h | 15 + 2 files changed, 360 insertions(+), 7 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m index fb8beaa151..4d69b956bf 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m @@ -782,6 +782,73 @@ - (void)testEncryptWorksForPubKeyCachedInWallet XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(myDid, @"invalid did"); + + + // 3. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 6. encrypt + NSData *encryptedMessage; + NSData *nonce; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:myDid + did:theirDid + message:message + outEncryptedMessage:&encryptedMessage + outNonce:&nonce]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testEncryptWorksForGetPubKeyFromLedger +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + // 2. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName @@ -796,29 +863,300 @@ - (void)testEncryptWorksForPubKeyCachedInWallet outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); XCTAssertTrue(trusteeDid, @"invalid did"); - // 4. my did + + // 3. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for their did"); + + + // 4. Build & Submit nym request + + NSString *nymRequest; + ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid + targetDid:theirDid + verkey:theirVerkey + alias:nil + role:nil + outRequest:&nymRequest]; + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:walletHandle + submitterDid:trusteeDid + requestJson:nymRequest + outResponseJson:nil]; + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\"}",theirDid]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 6. encrypt + NSData *encryptedMessage; + NSData *nonce; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:trusteeDid + did:theirDid + message:message + outEncryptedMessage:&encryptedMessage + outNonce:&nonce]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testEncryptWorksForGetNymFromLedger +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. trustee did + NSString *trusteeDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&trusteeDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(trusteeDid, @"invalid did"); + + + // 4. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for their did"); + + // 4. Build & Submit nym request + + NSString *nymRequest; + ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid + targetDid:theirDid + verkey:theirVerkey + alias:nil + role:nil + outRequest:&nymRequest]; + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:walletHandle + submitterDid:trusteeDid + requestJson:nymRequest + outResponseJson:nil]; + + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 6. encrypt + NSData *encryptedMessage; + NSData *nonce; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:trusteeDid + did:theirDid + message:message + outEncryptedMessage:&encryptedMessage + outNonce:&nonce]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testEncryptWorksForExriredNym +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + NSString *walletName = @"wallet1"; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + // 2. Create wallet + ret = [[WalletUtils sharedInstance] createWalletWithPoolName:poolName + walletName:walletName + xtype:nil + config:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createWalletWithPoolName failed"); + + // 3. Open wallet + NSString *config = @"{\"freshness_time\":1}"; + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] openWalletWithName:walletName + config:config + outHandle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:openWalletWithName failed"); + + // 4. trustee did + NSString *trusteeDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&trusteeDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(trusteeDid, @"invalid did"); + + + // 5. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for their did"); + + // 6. Build & Submit nym request + + NSString *nymRequest; + ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid + targetDid:theirDid + verkey:theirVerkey + alias:nil + role:nil + outRequest:&nymRequest]; + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:walletHandle + submitterDid:trusteeDid + requestJson:nymRequest + outResponseJson:nil]; + + // 7. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 8. encrypt + NSData *encryptedMessage; + NSData *nonce; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:trusteeDid + did:theirDid + message:message + outEncryptedMessage:&encryptedMessage + outNonce:&nonce]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); + + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testEncryptWorksForInvalidWalletHandle +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. my did NSString *myDid; - NSString *myVerKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle seed:[SignusUtils mySeed] outMyDid:&myDid - outMyVerkey:&myVerKey + outMyVerkey:nil outMyPk:nil]; XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); XCTAssertTrue(myDid, @"invalid did"); - XCTAssertTrue(myVerKey, @"invalid verkey"); + + // 4. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + // 5. store their did - NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",myDid, myVerKey]; + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",theirDid, theirVerkey]; ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); // 6. encrypt - + IndyHandle invalidPoolHandle = poolHandle + 1; + NSData *encryptedMessage; + NSData *nonce; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:invalidPoolHandle + myDid:myDid + did:theirDid + message:message + outEncryptedMessage:&encryptedMessage + outNonce:&nonce]; + XCTAssertEqual(ret.code, PoolLedgerInvalidPoolHandle, @"SignusUtils::encryptWithWalletHandle() returned wrong code"); [[PoolUtils sharedInstance] closeHandle:poolHandle]; [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h index 3dc9f658db..8da967771e 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h @@ -64,4 +64,19 @@ message:(NSData *)message signature:(NSData *)signature outVerified:(BOOL *)verified; + +- (NSError *)encryptWithWalletHandle:(IndyHandle)walletHandle + poolHandle:(IndyHandle)poolHandle + myDid:(NSString *)myDid + did:(NSString *)did + message:(NSData *)message + outEncryptedMessage:(NSData **)encryptedMessage + outNonce:(NSData **)nonce; + +- (NSError *)decryptWithWalletHandle:(IndyHandle)walletHandle + myDid:(NSString *)myDid + did:(NSString *)did + encryptedMessage:(NSData *)encryptedMessage + nonce:(NSData *)nonce + outDecryptedMessage:(NSData **)decryptedMessage; @end From 294403d88b9e1602c141429168c9d84853509939 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 12:39:13 +0300 Subject: [PATCH 06/29] iOS: Added signus high cases tests for decrypt Updated signus medium cases Verify tests --- .../Case Tests/Signus/SignusHighCases.m | 258 ++++++++++++++++++ .../Case Tests/Signus/SignusMediumCases.m | 168 ++++-------- 2 files changed, 315 insertions(+), 111 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m index 4d69b956bf..982d8b0e09 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m @@ -1166,6 +1166,264 @@ - (void)testEncryptWorksForInvalidWalletHandle // MARK: - Decrypt +- (void)testDecryptWorks +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(myDid, @"invalid did"); + + + // 3. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + + // 4. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 5. decrypt + + NSData *decryptedMessage; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle + myDid:myDid + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:[SignusUtils nonce] + outDecryptedMessage:&decryptedMessage]; + XCTAssertTrue([decryptedMessage isEqualToData:message], @"SignusUtils::decryptWithWalletHandle() failed. Decrypted mesage doesn't match message"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testDecryptWorksForOtherCoder +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. my did + NSString *myDid; + NSString *myVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&myDid + outMyVerkey:&myVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(myDid, @"invalid did"); + + + // 4. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + + // 5. store myDid + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", myDid, myVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 6. store theirDid + identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 7. encrypt + NSData *encryptedMessage; + NSData *nonce; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:myDid + did:myDid + message:message + outEncryptedMessage:&encryptedMessage + outNonce:&nonce]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); + + // 8. decrypt + + NSData *decryptedMessage; + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle + myDid:myDid + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:[SignusUtils nonce] + outDecryptedMessage:&decryptedMessage]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code."); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testDecryptWorksForNonceNotCorrespondMessage +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(myDid, @"invalid did"); + + + // 4. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed for theirDid"); + + // 6. decrypt + + NSString *nonce = @"acS2SQgDdfE3Goxa1AhcWCa4kEMqSelv7"; + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle + myDid:myDid + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:[nonce dataUsingEncoding:NSUTF8StringEncoding] + outDecryptedMessage:nil]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code."); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testDecryptWorksForInvalidWalletHandle +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(myDid, @"invalid did"); + + + // 4. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed for theirDid"); + + // 6. decrypt + + IndyHandle invalidWalletHandle = walletHandle + 1; + NSData *decryptedMessage; + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:invalidWalletHandle + myDid:myDid + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:[SignusUtils nonce] + outDecryptedMessage:&decryptedMessage]; + XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::decryptWithWalletHandle() returned wrong error code."); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} @end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m index 6365adae08..4f2c2937de 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m @@ -269,11 +269,11 @@ - (void)testSignWorksForInvalidMessage // MARK: - Verify -- (void)testVerifyWorksForInvalidMessage +- (void)testVerifyWorksForInvalidSignatureLen { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_invalid_message"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -293,88 +293,34 @@ - (void)testVerifyWorksForInvalidMessage // 3. create did NSString *did; NSString *verKey; - NSString *didJson = @"{\"seed\":\"000000000000000000000000Trustee1\"}"; - ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle - myDidJson:didJson - outMyDid:&did - outMyVerkey:&verKey - outMyPk:nil]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed"); - XCTAssertTrue(did, @"invalid did"); - XCTAssertTrue(verKey, @"invalid verKey"); + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&did + outMyVerkey:&verKey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for did"); - // 4. Store their did + // 4. Store did NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", did, verKey]; ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); // 5. Verify - NSString *message = @"1496822211362017764"; - + const unsigned char bytes[] = {187, 227, 10, 29, 46, 178, 12, 179, 197, 69, 171, 70, 228, 204, 52, 22, 199, 54, 62, 13, 115, 5, 216, 66, 20, 131, 121, 29, 251, 224, 253, 201, 75, 73, 225, 237, 219, 133, 35, 217, 131, 135, 232, 129, 32}; + NSData *signature = [NSData dataWithBytes:bytes length:sizeof(bytes)]; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; BOOL verified = NO; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:did - signature:message + message:message + signature:signature outVerified:&verified]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); - [TestUtils cleanupStorage]; -} - -- (void)testVerifyWorksForMessageWithoutSignature -{ - [TestUtils cleanupStorage]; - NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_message_without_signature"; - - // 1. Create and open pool ledger config, get pool handle - IndyHandle poolHandle = 0; - - ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName - poolHandle:&poolHandle]; - XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); - - - // 2. Create and open wallet, get wallet handle - IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName - xtype:nil - handle:&walletHandle]; - XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); - - // 3. create did - NSString *did; - NSString *verKey; - NSString *didJson = @"{\"seed\":\"000000000000000000000000Trustee1\"}"; - ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle - myDidJson:didJson - outMyDid:&did - outMyVerkey:&verKey - outMyPk:nil]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed"); - XCTAssertTrue(did, @"invalid did"); - XCTAssertTrue(verKey, @"invalid verKey"); - - // 4. Store their did - NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", did, verKey]; - ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle - identityJson:identityJson]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); - - // 5. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\"}"; - - BOOL verified = NO; - ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle - poolHandle:poolHandle - did:did - signature:message - outVerified:&verified]; - XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -383,7 +329,7 @@ - (void)testVerifyWorksForGetNymFromLedgerWithIncompatibleWallet { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_get_nym_from_ledger_with_incompatible_wallet"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -392,7 +338,6 @@ - (void)testVerifyWorksForGetNymFromLedgerWithIncompatibleWallet poolHandle:&poolHandle]; XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); - // 2. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"other_pool_name" @@ -401,43 +346,44 @@ - (void)testVerifyWorksForGetNymFromLedgerWithIncompatibleWallet XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); // 3. create did - NSString *myDid; - NSString *myDidJson = @"{\"seed\":\"00000000000000000000000000000My1\"}"; - ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle - myDidJson:myDidJson - outMyDid:&myDid - outMyVerkey:nil - outMyPk:nil]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed"); - XCTAssertTrue(myDid, @"invalid did"); + NSString *mydid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&mydid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); // 4. Store their did - NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\"}", myDid]; + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\"}", mydid]; ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 5. verify - // 5. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"identifier\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; - - BOOL verified = NO; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle - did:myDid - signature:message - outVerified:&verified]; - XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); + did:mydid + message:message + signature:[SignusUtils signature] + outVerified:nil]; + XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"SignusUtils::verifyWithWalletHandle() returned wrong error code"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } -- (void)testVerifyWorksForGetUnknownNymFromLedger + + +- (void)testVerifyWorksForGetLedgerNotFoundNym { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_get_unknow_nym_from_ledger"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -454,7 +400,7 @@ - (void)testVerifyWorksForGetUnknownNymFromLedger handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); - // 3. create did + // 3. create did NSString *myDid; NSString *myDidJson = @"{\"seed\":\"0000000000000000000000000000Fake\"}"; ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle @@ -463,7 +409,6 @@ - (void)testVerifyWorksForGetUnknownNymFromLedger outMyVerkey:nil outMyPk:nil]; XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed"); - XCTAssertTrue(myDid, @"invalid did"); // 4. Store their did NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\"}", myDid]; @@ -472,26 +417,28 @@ - (void)testVerifyWorksForGetUnknownNymFromLedger XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); // 5. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"identifier\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; + + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; BOOL verified = NO; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - signature:message + message:message + signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, CommonInvalidState, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } -- (void)testIndyVerifyWorksForUnknownNym +- (void)testVerifyWorksForGetNymFromLedger { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"indy_verify_works_for_unknown_nym"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -500,7 +447,6 @@ - (void)testIndyVerifyWorksForUnknownNym poolHandle:&poolHandle]; XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); - // 2. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName @@ -508,21 +454,20 @@ - (void)testIndyVerifyWorksForUnknownNym handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); - // 3. create trustee did + // 3. create & store trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:@"000000000000000000000000Trustee1" + seed:[SignusUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); - XCTAssertTrue(trusteeDid, @"invalid trustee"); // 4. create my did NSString *myDid; NSString *myVerKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:@"00000000000000000000000000000My1" + seed:[SignusUtils mySeed] outMyDid:&myDid outMyVerkey:&myVerKey outMyPk:nil]; @@ -551,19 +496,20 @@ - (void)testIndyVerifyWorksForUnknownNym XCTAssertTrue([nymResponse isValid], @"invalid nymResponse"); // 7. Verify - NSString *message = @"{"\ - "\"reqId\":1496822211362017764,"\ - "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; BOOL verified = NO; + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - signature:message + message:message + signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified); + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } From f54354a2eeb6d1ca11465bb9da30dc558230c126 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 13:45:44 +0300 Subject: [PATCH 07/29] iOS: Added signus encrypt and decrypt medium cases tests --- .../Case Tests/Signus/SignusMediumCases.m | 384 ++++++++++++++++++ 1 file changed, 384 insertions(+) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m index 4f2c2937de..5f5015b804 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m @@ -510,6 +510,390 @@ - (void)testVerifyWorksForGetNymFromLedger [[PoolUtils sharedInstance] closeHandle:poolHandle]; [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +// MARK: - Encrypt + +- (void)testEncryptWorksForUnknownmyDid +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. create and store their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for theirDid"); + + // 4. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 5. encrypt + + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:@"unknownDid" + did:theirDid + message:message + outEncryptedMessage:nil + outNonce:nil]; + XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testEncryptWorksForGetNymFromLedgerWithIncompatiblePool +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"other_pool" + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. create and store myDid + + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + + // 4. create and store their did + NSString *theirDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&theirDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for theirDid"); + + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\"}", theirDid]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 6. encrypt + + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:myDid + did:theirDid + message:message + outEncryptedMessage:nil + outNonce:nil]; + XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testEncryptWorksForNotFoundNym +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. create and store myDid + + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + + // 4. create and store their did + NSString *theirDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&theirDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for theirDid"); + + // 6. encrypt + + NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle + poolHandle:poolHandle + myDid:myDid + did:theirDid + message:message + outEncryptedMessage:nil + outNonce:nil]; + XCTAssertEqual(ret.code, CommonInvalidState, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +// MARK: - Decrypt + +- (void)testDecryptWorksForUnknownMyDid +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. create their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for theirDid"); + + // 3. store their did + + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 4. decrypt + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle + myDid:@"unknownDid" + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:[SignusUtils nonce] + outDecryptedMessage:nil]; + XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testDecryptworksForUnknownCoderDid +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. create my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + + // 3. create their did + NSString *theirDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for theirDid"); + + // 4. decrypt + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle + myDid:myDid + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:[SignusUtils nonce] + outDecryptedMessage:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testDecryptWorksForSavedCoderNymWithoutPubKey +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. create my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + + // 3. create their did + NSString *theirDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for theirDid"); + + // 4. store their did + + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\"}", theirDid]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 5. decrypt + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle + myDid:myDid + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:[SignusUtils nonce] + outDecryptedMessage:nil]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +-(void)testDecryptWorksForInvalidNonceLen +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. create my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + + // 3. create their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for theirDid"); + + // 4. store their did + + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}", theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + + // 5. decrypt + + const unsigned char bytes[] = {24, 99, 107, 70, 58, 6, 252, 149, 225}; + NSData *nonce = [NSData dataWithBytes:bytes length:sizeof(bytes)]; + + ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle + myDid:myDid + did:theirDid + encryptedMessage:[SignusUtils encryptedMessage] + nonce:nonce + outDecryptedMessage:nil]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; } From ee686908412b9861ef4cd44b25b117ba014ad044 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 15:54:34 +0300 Subject: [PATCH 08/29] iOS: Added new signus tests --- .../Case Tests/Signus/SignusHighCases.m | 194 +++++++++++++++--- .../Case Tests/Signus/SignusMediumCases.m | 138 ++++++++----- .../Demo Tests/SignusDemo.mm | 97 +++++---- .../Test Utils/SignusUtils.h | 2 +- .../Test Utils/SignusUtils.mm | 13 +- 5 files changed, 317 insertions(+), 127 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m index 982d8b0e09..d468b68d3c 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m @@ -380,10 +380,9 @@ - (void)testSignWorks // 3. Sign NSData *signature; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle theirDid:myDid - message:message + message:[SignusUtils message] outSignature:&signature]; XCTAssertTrue([signature isEqualToData:[SignusUtils signature]], @"SignusUtils::signWithWalletHandle() failed. Signature is not verified"); @@ -403,10 +402,9 @@ - (void)testSignWorksForUnknownSigner XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); NSData *signature; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle theirDid:@"did" - message:message + message:[SignusUtils message] outSignature:&signature]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::signWithWalletHandle() returned wrong error"); @@ -436,11 +434,10 @@ - (void)testSignWorksForInvalidWalletHandle // 3. Sign NSData *signature; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; IndyHandle invalidWalletHandle = walletHandle + 1; ret = [[SignusUtils sharedInstance] signWithWalletHandle:invalidWalletHandle theirDid:myDid - message:message + message:[SignusUtils message] outSignature:&signature]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::signWithWalletHandle() returned wrong code"); @@ -491,12 +488,11 @@ - (void)testVerifyWorksForVerkeyCachedInWallet XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); // 5. Verify - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; BOOL verified = NO; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:did - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -577,11 +573,10 @@ - (void)testVerifyWorksForGetVerkeyFromLedger // 8. Verify BOOL verified = NO; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -670,11 +665,10 @@ - (void)testVerifyWorksForExpiredNym // 8. Verify BOOL verified = NO; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -711,12 +705,11 @@ - (void)testVerifyWorksForInvalidWalletHandle // 3. Verify BOOL verified = NO; - NSData * message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; IndyHandle invalidWalletHandle = walletHandle + 1; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:invalidWalletHandle poolHandle:poolHandle did:@"did" - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -750,12 +743,11 @@ - (void)testVerifyWorksForInvalidPoolHandle // 3. Verify BOOL verified = NO; - NSData * message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; IndyHandle invalidPoolHandle = poolHandle + 1; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:invalidPoolHandle did:@"did" - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, PoolLedgerInvalidPoolHandle, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -766,6 +758,86 @@ - (void)testVerifyWorksForInvalidPoolHandle [TestUtils cleanupStorage]; } +- (void)testVerifyWorksForOtherSigner +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. my did + NSString *did; + NSString *verKey; + NSString *didJson = [NSString stringWithFormat:@"{\"seed\":\"%@\"}", [SignusUtils trusteeSeed]]; + ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle + myDidJson:didJson + outMyDid:&did + outMyVerkey:&verKey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed for myDid"); + + // 4. other did + NSString *otherDid; + NSString *otherVerKey; + NSString *otherDidJson = @"{\"seed\":\"000000000000000000000000Steward1\"}"; + ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle + myDidJson:otherDidJson + outMyDid:&otherDid + outMyVerkey:&otherVerKey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed for otherDid"); + + // 5. Store my did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",did, verKey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed for did"); + + // 6. Store my did + identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",otherDid, otherVerKey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed for otherDid"); + + // 7. Sign + + NSData *signature; + ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle + theirDid:did + message:[SignusUtils message] + outSignature:&signature]; + + // 8. verify + + BOOL isValid = NO; + ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle + poolHandle:poolHandle + did:otherDid + message:[SignusUtils message] + signature:signature + outVerified:&isValid]; + XCTAssertTrue(isValid, @"SignusUtils::verifyWithWalletHandle failed. Signature is not valid"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + // MARK: - Encrypt - (void)testEncryptWorksForPubKeyCachedInWallet @@ -819,12 +891,11 @@ - (void)testEncryptWorksForPubKeyCachedInWallet // 6. encrypt NSData *encryptedMessage; NSData *nonce; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:myDid did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -902,12 +973,11 @@ - (void)testEncryptWorksForGetPubKeyFromLedger // 6. encrypt NSData *encryptedMessage; NSData *nonce; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:trusteeDid did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -986,12 +1056,11 @@ - (void)testEncryptWorksForGetNymFromLedger // 6. encrypt NSData *encryptedMessage; NSData *nonce; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:trusteeDid did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -1078,12 +1147,11 @@ - (void)testEncryptWorksForExriredNym // 8. encrypt NSData *encryptedMessage; NSData *nonce; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:trusteeDid did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -1144,16 +1212,83 @@ - (void)testEncryptWorksForInvalidWalletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + // 6. encrypt + IndyHandle invalidWalletHandle = walletHandle + 1; + NSData *encryptedMessage; + NSData *nonce; + ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:invalidWalletHandle + poolHandle:poolHandle + myDid:myDid + did:theirDid + message:[SignusUtils message] + outEncryptedMessage:&encryptedMessage + outNonce:&nonce]; + XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::encryptWithWalletHandle() returned wrong code"); + + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testEncryptWorksForInvalidPoolHandle +{ + [TestUtils cleanupStorage]; + + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; + + // 1. Create and open pool ledger config, get pool handle + IndyHandle poolHandle = 0; + + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils:createAndOpenPoolLedgerConfig:poolName failed"); + + + // 2. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 3. my did + NSString *myDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils mySeed] + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for myDid"); + XCTAssertTrue(myDid, @"invalid did"); + + + // 4. their did + NSString *theirDid; + NSString *theirVerkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:[SignusUtils trusteeSeed] + outMyDid:&theirDid + outMyVerkey:&theirVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + + // 5. store their did + NSString *identityJson = [NSString stringWithFormat:@"{\"did\":\"%@\", \"verkey\":\"%@\"}",theirDid, theirVerkey]; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidWithWalletHandle() failed"); + // 6. encrypt IndyHandle invalidPoolHandle = poolHandle + 1; NSData *encryptedMessage; NSData *nonce; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:invalidPoolHandle myDid:myDid did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, PoolLedgerInvalidPoolHandle, @"SignusUtils::encryptWithWalletHandle() returned wrong code"); @@ -1164,6 +1299,7 @@ - (void)testEncryptWorksForInvalidWalletHandle [TestUtils cleanupStorage]; } + // MARK: - Decrypt - (void)testDecryptWorks @@ -1210,14 +1346,13 @@ - (void)testDecryptWorks // 5. decrypt NSData *decryptedMessage; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:myDid did:theirDid encryptedMessage:[SignusUtils encryptedMessage] nonce:[SignusUtils nonce] outDecryptedMessage:&decryptedMessage]; - XCTAssertTrue([decryptedMessage isEqualToData:message], @"SignusUtils::decryptWithWalletHandle() failed. Decrypted mesage doesn't match message"); + XCTAssertTrue([decryptedMessage isEqualToData:[SignusUtils message]], @"SignusUtils::decryptWithWalletHandle() failed. Decrypted mesage doesn't match message"); [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; @@ -1283,12 +1418,11 @@ - (void)testDecryptWorksForOtherCoder // 7. encrypt NSData *encryptedMessage; NSData *nonce; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:myDid did:myDid - message:message + message:[SignusUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m index 5f5015b804..d6a4304285 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m @@ -142,7 +142,7 @@ -(void)testReplaceKeysWorksForNotExistingDid { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -164,13 +164,51 @@ -(void)testReplaceKeysWorksForNotExistingDid [TestUtils cleanupStorage]; } -// MARK: - Store their did +- (void)testReplaceKeysWorksForCorectCryptoType +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + NSString *poolName = [SignusUtils pool]; -- (void)testStoreTheirDidWorksForInvalidCryptoType + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. create my did + + NSString *myDid; + NSString *myVerkey; + ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle + myDidJson:@"{}" + outMyDid:&myDid + outMyVerkey:&myVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils:createMyDidWithWalletHandle failed"); + + // 3. replace keys + + NSString *newVerkey; + ret = [[SignusUtils sharedInstance] replaceKeysWithWalletHandle:walletHandle + did:myDid + identityJson:@"{\"crypto_type\":\"ed25519\"}" + outMyVerKey:&newVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils:replaceKeysWithWalletHandle failed"); + XCTAssertFalse([myVerkey isEqualToString:newVerkey], @"myVerkey is equal to newVerkey"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testReplaceKeysWorksForInvalidCryptoType { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [SignusUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -179,16 +217,35 @@ - (void)testStoreTheirDidWorksForInvalidCryptoType handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); - // 2. Store their did - NSString *identityJson = @"{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", \"crypto_type\":\"type\"}"; - ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle - identityJson:identityJson]; - XCTAssertEqual(ret.code, SignusUnknownCryptoError, @"SignusUtils:storeTheirDidWithWalletHandle failed"); + // 2. create my did + + NSString *myDid; + ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle + myDidJson:@"{}" + outMyDid:&myDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils:createMyDidWithWalletHandle failed"); + + // 3. replace keys + + NSString *myVerkey; + ret = [[SignusUtils sharedInstance] replaceKeysWithWalletHandle:walletHandle + did:myDid + identityJson:@"{\"crypto_type\":\"type\"}" + outMyVerKey:&myVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, SignusUnknownCryptoError, @"SignusUtils:replaceKeysWithWalletHandle returned wrong error code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; + } -- (void)testStoreTheirDidWorksForInvalidDid +// MARK: - Store their did + +- (void)testStoreTheirDidWorksForInvalidCryptoType { [TestUtils cleanupStorage]; NSError *ret = nil; @@ -202,15 +259,15 @@ - (void)testStoreTheirDidWorksForInvalidDid XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); // 2. Store their did - NSString *identityJson = @"{\"did\":\"invalid_base58_string\"}"; + NSString *identityJson = @"{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", \"crypto_type\":\"type\"}"; ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; - XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils:storeTheirDidWithWalletHandle returned wrong code"); + XCTAssertEqual(ret.code, SignusUnknownCryptoError, @"SignusUtils:storeTheirDidWithWalletHandle failed"); [TestUtils cleanupStorage]; } -- (void)testStoreTheirDidWorksForInvalidVerkey +- (void)testStoreTheirDidWorksForInvalidDid { [TestUtils cleanupStorage]; NSError *ret = nil; @@ -224,7 +281,7 @@ - (void)testStoreTheirDidWorksForInvalidVerkey XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); // 2. Store their did - NSString *identityJson = @"{\"did\":\"did\", \"verkey\":\"verkey\"}"; + NSString *identityJson = @"{\"did\":\"invalid_base58_string\"}"; ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils:storeTheirDidWithWalletHandle returned wrong code"); @@ -232,37 +289,24 @@ - (void)testStoreTheirDidWorksForInvalidVerkey [TestUtils cleanupStorage]; } -// MARK: - Sign - -- (void)testSignWorksForInvalidMessage +- (void)testStoreTheirDidWorksForInvalidVerkey { [TestUtils cleanupStorage]; NSError *ret = nil; + NSString *poolName = @"pool1"; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); - // 2. create my did - NSString *myDid; - NSString *myDidJson = @"{}"; - ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle - myDidJson:myDidJson - outMyDid:&myDid - outMyVerkey:nil - outMyPk:nil]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() failed"); - - // 3. Sign - NSString *message = @"1495034346617224651"; - - ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle - theirDid:myDid message:message - outSignature:nil]; - XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::signWithWalletHandle() returned wrong code"); + // 2. Store their did + NSString *identityJson = @"{\"did\":\"did\", \"verkey\":\"verkey\"}"; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils:storeTheirDidWithWalletHandle returned wrong code"); [TestUtils cleanupStorage]; } @@ -309,12 +353,11 @@ - (void)testVerifyWorksForInvalidSignatureLen // 5. Verify const unsigned char bytes[] = {187, 227, 10, 29, 46, 178, 12, 179, 197, 69, 171, 70, 228, 204, 52, 22, 199, 54, 62, 13, 115, 5, 216, 66, 20, 131, 121, 29, 251, 224, 253, 201, 75, 73, 225, 237, 219, 133, 35, 217, 131, 135, 232, 129, 32}; NSData *signature = [NSData dataWithBytes:bytes length:sizeof(bytes)]; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; BOOL verified = NO; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:did - message:message + message:[SignusUtils message] signature:signature outVerified:&verified]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); @@ -362,11 +405,10 @@ - (void)testVerifyWorksForGetNymFromLedgerWithIncompatibleWallet // 5. verify - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:mydid - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:nil]; XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"SignusUtils::verifyWithWalletHandle() returned wrong error code"); @@ -418,13 +460,11 @@ - (void)testVerifyWorksForGetLedgerNotFoundNym // 5. Verify - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; - BOOL verified = NO; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, CommonInvalidState, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); @@ -498,11 +538,10 @@ - (void)testVerifyWorksForGetNymFromLedger // 7. Verify BOOL verified = NO; - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:message + message:[SignusUtils message] signature:[SignusUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -555,12 +594,11 @@ - (void)testEncryptWorksForUnknownmyDid // 5. encrypt - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:@"unknownDid" did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:nil outNonce:nil]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); @@ -619,12 +657,11 @@ - (void)testEncryptWorksForGetNymFromLedgerWithIncompatiblePool // 6. encrypt - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:myDid did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:nil outNonce:nil]; XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); @@ -677,12 +714,11 @@ - (void)testEncryptWorksForNotFoundNym // 6. encrypt - NSData *message = [[SignusUtils message] dataUsingEncoding:NSUTF8StringEncoding]; ret = [[SignusUtils sharedInstance] encryptWithWalletHandle:walletHandle poolHandle:poolHandle myDid:myDid did:theirDid - message:message + message:[SignusUtils message] outEncryptedMessage:nil outNonce:nil]; XCTAssertEqual(ret.code, CommonInvalidState, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); @@ -779,7 +815,7 @@ - (void)testDecryptworksForUnknownCoderDid encryptedMessage:[SignusUtils encryptedMessage] nonce:[SignusUtils nonce] outDecryptedMessage:nil]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); + XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm index c10f477700..32eaf9c036 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm @@ -33,6 +33,9 @@ - (void)testSignusDemo [TestUtils cleanupStorage]; NSString *poolName = @"pool1"; + NSString *myWalletName = @"my_wallet4"; + NSString *theirWalletName = @"their_wallet5"; + NSString *xtype = @"default"; NSError *ret = nil; XCTestExpectation* completionExpectation = nil; @@ -40,22 +43,35 @@ - (void)testSignusDemo IndyHandle theirWalletHandle = 0; //TODO CREATE ISSUER, PROVER, VERIFIER WALLETS - //1. Create and open my wallet - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName: poolName - xtype: nil - handle: &myWalletHandle]; + //1. Create my wallet + ret = [[WalletUtils sharedInstance] createWalletWithPoolName:poolName + walletName:myWalletName + xtype:xtype + config:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createWalletWithPoolName() failed for my wallet!"); - XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed!"); + // 2. Open my wallet + ret = [[WalletUtils sharedInstance] openWalletWithName:myWalletName + config:nil + outHandle:&myWalletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::openWalletWithName() failed for my wallet!"); - //2. Create and open Their Wallet - - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName: poolName - xtype: nil - handle: &theirWalletHandle]; + // 3. Create Their Wallet - XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed!"); - - // 3. Create My DID + ret = [[WalletUtils sharedInstance] createWalletWithPoolName:poolName + walletName:theirWalletName + xtype:xtype + config:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createWalletWithPoolName() failed for their wallet!"); + + // 4. Open their wallet + + ret = [[WalletUtils sharedInstance] openWalletWithName:theirWalletName + config:nil + outHandle:&theirWalletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::openWalletWithName() failed for their wallet!"); + + // 5. Create My DID NSString *myDidJson = @"{}"; completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; @@ -81,7 +97,7 @@ - (void)testSignusDemo [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; XCTAssertEqual(ret.code, Success, @"createAndStoreMyDid() failed!"); - // 4. Create Their DID + // 6. Create Their DID NSString *theirDidJson = @"{}"; completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; @@ -108,7 +124,7 @@ - (void)testSignusDemo [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; XCTAssertEqual(ret.code, Success, @"createAndStoreMyDid() failed!"); - // 5. Store Their DID + // 7. Store Their DID NSString* theirIdentityJson = [NSString stringWithFormat: @"{\"did\":\"%@\",\ \"pk\":\"%@\",\ @@ -126,48 +142,51 @@ - (void)testSignusDemo [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; XCTAssertEqual(ret.code, Success, @"createAndStoreMyDid() failed!"); - // 6. Their Sign message + // 8. Their Sign message - NSString* message = @"{"\ + NSString* messageJson = @"{"\ " \"reqId\":1495034346617224651," " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\"," " \"operation\":{" " \"type\":\"1\"," " \"dest\":\"4efZu2SXufS556yss7W5k6Po37jt4371RM4whbPKBKdB\"}" "}"; + NSData *message = [messageJson dataUsingEncoding:NSUTF8StringEncoding]; completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; - __block NSString *theirSignature = nil; + __block NSData *signature = nil; - ret = [IndySignus signWithWalletHandle: theirWalletHandle - did: theirDid - msg: message - completion: ^(NSError *error, NSString *signature) - { - XCTAssertEqual(error.code, Success, "sign() got error in completion"); - NSLog(@"signature: %@", signature); - theirSignature = [NSString stringWithString: signature]; - [completionExpectation fulfill]; - }]; + ret = [IndySignus signWithWalletHandle:theirWalletHandle + did:theirDid + message:message + completion:^(NSError *error, NSData *blockSignature) + { + XCTAssertEqual(error.code, Success, "sign() got error in completion"); + NSLog(@"signature: %@", signature); + signature = blockSignature; + [completionExpectation fulfill]; + }]; + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; XCTAssertEqual(ret.code, Success, @"sign() failed!"); - // 7. I Verify message + // 9. I Verify message IndyHandle poolHandle = 1; completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; - ret = [IndySignus verifySignatureWithWalletHandle: myWalletHandle - poolHandle: poolHandle - did: theirDid - signature: theirSignature - completion: ^(NSError *error, BOOL valid) - { - XCTAssertEqual(error.code, Success, "verifySignature() got error in completion"); - XCTAssertEqual(YES, valid, "verifySignature() signature is not valid"); - [completionExpectation fulfill]; - }]; + ret = [IndySignus verifySignatureWithWalletHandle:myWalletHandle + poolHandle:poolHandle + did:theirDid + message:message + signature:signature + completion:^(NSError *error, BOOL valid) + { + XCTAssertEqual(error.code, Success, "verifySignature() got error in completion"); + XCTAssertEqual(YES, valid, "verifySignature() signature is not valid"); + [completionExpectation fulfill]; + }]; // TODO: There is some error inside closure at rust level [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h index 8da967771e..bf07be2485 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h @@ -17,7 +17,7 @@ // MARK: - Class variables + (NSString *)pool; -+ (NSString *)message; ++ (NSData *)message; + (NSData *)encryptedMessage; + (NSData *)nonce; + (NSData *)signature; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm index 8c8d00fdb8..962f0bd5ab 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.mm @@ -30,20 +30,21 @@ + (NSString *)pool return @"pool_1"; } -+ (NSString *)message ++ (NSData *)message { - return @"{\"reqId\":1496822211362017764}"; + NSString *messageJson = @"{\"reqId\":1496822211362017764}"; + return [messageJson dataUsingEncoding:NSUTF8StringEncoding]; } + (NSData *)encryptedMessage { - const unsigned char bytes[] = {242, 246, 53, 153, 106, 37, 185, 65, 212, 14, 109, 131, 200, 169, 94, 110, 51, 47, 101, 89, 0, 171, 105, 183}; + const unsigned char bytes[] = {187, 227, 10, 29, 46, 178, 12, 179, 197, 69, 171, 70, 228, 204, 52, 22, 199, 54, 62, 13, 115, 5, 216, 66, 20, 131, 121, 29, 251, 224, 253, 201, 75, 73, 225, 237, 219, 133, 35, 217, 131, 135, 232, 129, 32}; return [NSData dataWithBytes:bytes length:sizeof(bytes)]; } + (NSData *)nonce { - const unsigned char bytes[] = {187, 227, 10, 29, 46, 178, 12, 179, 197, 69, 171, 70, 228, 204, 52, 22, 199, 54, 62, 13, 115, 5, 216, 66, 20, 131, 121, 29, 251, 224, 253, 201, 75, 73, 225, 237, 219, 133, 35, 217, 131, 135, 232, 129, 32}; + const unsigned char bytes[] = {242, 246, 53, 153, 106, 37, 185, 65, 212, 14, 109, 131, 200, 169, 94, 110, 51, 47, 101, 89, 0, 171, 105, 183}; return [NSData dataWithBytes:bytes length:sizeof(bytes)]; } @@ -55,12 +56,12 @@ + (NSData *)signature + (NSString *)trusteeSeed { - return @"000000000000000000000000"; + return @"000000000000000000000000Trustee1"; } + (NSString *)mySeed { - return @"00000000000000000000000000000"; + return @"00000000000000000000000000000My1"; } - (NSError *)signWithWalletHandle:(IndyHandle)walletHandle From 0de090a8868c238045cac438428ef27c17f0b15b Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 17:22:42 +0300 Subject: [PATCH 09/29] iOS: Added testAgentListenWorksForGetSenderDataFromLedger test to Agent moved common variables to TestUtils class --- .../Case Tests/Agent/AgentHighCases.m | 148 ++++++++++++++++++ .../Case Tests/Signus/SignusHighCases.m | 144 ++++++++--------- .../Case Tests/Signus/SignusMediumCases.m | 84 +++++----- .../Test Utils/SignusUtils.h | 10 -- .../libindy-demoTests/Test Utils/TestUtils.h | 11 ++ .../libindy-demoTests/Test Utils/TestUtils.m | 54 +++++++ 6 files changed, 327 insertions(+), 124 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m index 138214038c..27434c673f 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m @@ -323,6 +323,154 @@ - (void)testAgentListenWorksForAllDataInWalletPresent [TestUtils cleanupStorage]; } +- (void)testAgentListenWorksForGetSenderDataFromLedger +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. create and open trustee wallet + + IndyHandle trusteeWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&trusteeWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for trusteeWallet"); + IndyHandle listenerWallet = trusteeWallet; + + // 3. create and open sender wallet + + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for senderWallet"); + + // 4. create and store trusteeDid + NSString *trusteeDid; + NSString *trusteeVerkey; + NSString *trusteePk; + + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:trusteeWallet + seed:[TestUtils trusteeSeed] + outMyDid:&trusteeDid + outMyVerkey:&trusteeVerkey + outMyPk:&trusteePk]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trusteeDid"); + + // 5. create and store senderDid + NSString *senderDid; + NSString *senderVerkey; + NSString *senderPk; + + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:[TestUtils trusteeSeed] + outMyDid:&senderDid + outMyVerkey:&senderVerkey + outMyPk:&senderPk]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for senderDid"); + + // 6. create and store listenerDid + NSString *listenerDid; + NSString *listenerVerkey; + NSString *listenerPk; + + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:trusteeWallet + seed:[TestUtils trusteeSeed] + outMyDid:&listenerDid + outMyVerkey:&listenerVerkey + outMyPk:&listenerPk]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for listenerDid"); + + // 7 Build & submit nym request + + NSString *senderNymJson; + ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid + targetDid:senderDid + verkey:senderVerkey + alias:nil + role:nil + outRequest:&senderNymJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildNymRequestWithSubmitterDid() failed"); + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:trusteeWallet + submitterDid:trusteeDid + requestJson:senderNymJson + outResponseJson:nil]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for senderNymJson"); + + // 8. Build & submit attribute request + NSString *raw = [NSString stringWithFormat:@"{\"endpoint\":{\"ha\":\"%@\", \"verkey\":\"%@\"}}",[TestUtils endpoint], senderPk]; + NSString *senderAttribJson; + ret = [[LedgerUtils sharedInstance] buildAttribRequestWithSubmitterDid:senderDid + targetDid:senderDid + hash:nil + raw:raw + enc:nil + resultJson:&senderAttribJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildAttribRequestWithSubmitterDid() failed"); + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:senderWallet + submitterDid:senderDid + requestJson:senderAttribJson + outResponseJson:nil]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for senderAttribJson"); + + // 9. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 10. add identity + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 11. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:senderWallet + theirDid:listenerDid + theirPk:listenerPk + theirVerkey:listenerVerkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 12. connect + + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + + // 13. Close + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + // MARK: - Add identity - (void)testAgentAddIdentityWorks diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m index d468b68d3c..1b079bf020 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m @@ -362,14 +362,14 @@ - (void)testSignWorks // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[SignusUtils pool] + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); // 2. create my did NSString *myDid; - NSString *myDidJson = [NSString stringWithFormat:@"{\"seed\":\"%@\"}",[SignusUtils mySeed]]; + NSString *myDidJson = [NSString stringWithFormat:@"{\"seed\":\"%@\"}",[TestUtils mySeed]]; ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle myDidJson:myDidJson outMyDid:&myDid @@ -382,9 +382,9 @@ - (void)testSignWorks NSData *signature; ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle theirDid:myDid - message:[SignusUtils message] + message:[TestUtils message] outSignature:&signature]; - XCTAssertTrue([signature isEqualToData:[SignusUtils signature]], @"SignusUtils::signWithWalletHandle() failed. Signature is not verified"); + XCTAssertTrue([signature isEqualToData:[TestUtils signature]], @"SignusUtils::signWithWalletHandle() failed. Signature is not verified"); [TestUtils cleanupStorage]; } @@ -396,7 +396,7 @@ - (void)testSignWorksForUnknownSigner // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[SignusUtils pool] + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -404,7 +404,7 @@ - (void)testSignWorksForUnknownSigner NSData *signature; ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle theirDid:@"did" - message:[SignusUtils message] + message:[TestUtils message] outSignature:&signature]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::signWithWalletHandle() returned wrong error"); @@ -418,7 +418,7 @@ - (void)testSignWorksForInvalidWalletHandle // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[SignusUtils pool] + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -437,7 +437,7 @@ - (void)testSignWorksForInvalidWalletHandle IndyHandle invalidWalletHandle = walletHandle + 1; ret = [[SignusUtils sharedInstance] signWithWalletHandle:invalidWalletHandle theirDid:myDid - message:[SignusUtils message] + message:[TestUtils message] outSignature:&signature]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::signWithWalletHandle() returned wrong code"); @@ -452,7 +452,7 @@ - (void)testVerifyWorksForVerkeyCachedInWallet { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -473,7 +473,7 @@ - (void)testVerifyWorksForVerkeyCachedInWallet NSString *did; NSString *verKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&did outMyVerkey:&verKey outMyPk:nil]; @@ -492,8 +492,8 @@ - (void)testVerifyWorksForVerkeyCachedInWallet ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:did - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified, @"verifying failed"); @@ -508,7 +508,7 @@ - (void)testVerifyWorksForGetVerkeyFromLedger { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -528,7 +528,7 @@ - (void)testVerifyWorksForGetVerkeyFromLedger // 3. trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -539,7 +539,7 @@ - (void)testVerifyWorksForGetVerkeyFromLedger NSString *myDid; NSString *myVerKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:&myVerKey outMyPk:nil]; @@ -576,8 +576,8 @@ - (void)testVerifyWorksForGetVerkeyFromLedger ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified, @"verifying failed"); @@ -592,7 +592,7 @@ - (void)testVerifyWorksForExpiredNym { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; NSString *walletName = @"wallet1"; // 1. Create and open pool ledger config, get pool handle @@ -620,7 +620,7 @@ - (void)testVerifyWorksForExpiredNym // 4. trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -631,7 +631,7 @@ - (void)testVerifyWorksForExpiredNym NSString *myDid; NSString *myVerKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:&myVerKey outMyPk:nil]; @@ -668,8 +668,8 @@ - (void)testVerifyWorksForExpiredNym ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified, @"verifying failed"); @@ -685,7 +685,7 @@ - (void)testVerifyWorksForInvalidWalletHandle { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -709,8 +709,8 @@ - (void)testVerifyWorksForInvalidWalletHandle ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:invalidWalletHandle poolHandle:poolHandle did:@"did" - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -724,7 +724,7 @@ - (void)testVerifyWorksForInvalidPoolHandle { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -747,8 +747,8 @@ - (void)testVerifyWorksForInvalidPoolHandle ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:invalidPoolHandle did:@"did" - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, PoolLedgerInvalidPoolHandle, @"SignusUtils::verifyWithWalletHandle() failed"); @@ -762,7 +762,7 @@ - (void)testVerifyWorksForOtherSigner { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -782,7 +782,7 @@ - (void)testVerifyWorksForOtherSigner // 3. my did NSString *did; NSString *verKey; - NSString *didJson = [NSString stringWithFormat:@"{\"seed\":\"%@\"}", [SignusUtils trusteeSeed]]; + NSString *didJson = [NSString stringWithFormat:@"{\"seed\":\"%@\"}", [TestUtils trusteeSeed]]; ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle myDidJson:didJson outMyDid:&did @@ -818,7 +818,7 @@ - (void)testVerifyWorksForOtherSigner NSData *signature; ret = [[SignusUtils sharedInstance] signWithWalletHandle:walletHandle theirDid:did - message:[SignusUtils message] + message:[TestUtils message] outSignature:&signature]; // 8. verify @@ -827,7 +827,7 @@ - (void)testVerifyWorksForOtherSigner ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:otherDid - message:[SignusUtils message] + message:[TestUtils message] signature:signature outVerified:&isValid]; XCTAssertTrue(isValid, @"SignusUtils::verifyWithWalletHandle failed. Signature is not valid"); @@ -844,7 +844,7 @@ - (void)testEncryptWorksForPubKeyCachedInWallet { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -864,7 +864,7 @@ - (void)testEncryptWorksForPubKeyCachedInWallet // 3. my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -876,7 +876,7 @@ - (void)testEncryptWorksForPubKeyCachedInWallet NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -895,7 +895,7 @@ - (void)testEncryptWorksForPubKeyCachedInWallet poolHandle:poolHandle myDid:myDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -910,7 +910,7 @@ - (void)testEncryptWorksForGetPubKeyFromLedger { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -930,7 +930,7 @@ - (void)testEncryptWorksForGetPubKeyFromLedger // 3. trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -977,7 +977,7 @@ - (void)testEncryptWorksForGetPubKeyFromLedger poolHandle:poolHandle myDid:trusteeDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -993,7 +993,7 @@ - (void)testEncryptWorksForGetNymFromLedger [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -1013,7 +1013,7 @@ - (void)testEncryptWorksForGetNymFromLedger // 3. trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -1060,7 +1060,7 @@ - (void)testEncryptWorksForGetNymFromLedger poolHandle:poolHandle myDid:trusteeDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -1076,7 +1076,7 @@ - (void)testEncryptWorksForExriredNym [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; NSString *walletName = @"wallet1"; // 1. Create and open pool ledger config, get pool handle @@ -1104,7 +1104,7 @@ - (void)testEncryptWorksForExriredNym // 4. trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -1151,7 +1151,7 @@ - (void)testEncryptWorksForExriredNym poolHandle:poolHandle myDid:trusteeDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -1168,7 +1168,7 @@ - (void)testEncryptWorksForInvalidWalletHandle [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -1188,7 +1188,7 @@ - (void)testEncryptWorksForInvalidWalletHandle // 3. my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -1200,7 +1200,7 @@ - (void)testEncryptWorksForInvalidWalletHandle NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -1220,7 +1220,7 @@ - (void)testEncryptWorksForInvalidWalletHandle poolHandle:poolHandle myDid:myDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::encryptWithWalletHandle() returned wrong code"); @@ -1236,7 +1236,7 @@ - (void)testEncryptWorksForInvalidPoolHandle [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -1256,7 +1256,7 @@ - (void)testEncryptWorksForInvalidPoolHandle // 3. my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -1268,7 +1268,7 @@ - (void)testEncryptWorksForInvalidPoolHandle NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -1288,7 +1288,7 @@ - (void)testEncryptWorksForInvalidPoolHandle poolHandle:invalidPoolHandle myDid:myDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, PoolLedgerInvalidPoolHandle, @"SignusUtils::encryptWithWalletHandle() returned wrong code"); @@ -1307,7 +1307,7 @@ - (void)testDecryptWorks [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -1319,7 +1319,7 @@ - (void)testDecryptWorks // 2. my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -1331,7 +1331,7 @@ - (void)testDecryptWorks NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -1349,10 +1349,10 @@ - (void)testDecryptWorks ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:myDid did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] - nonce:[SignusUtils nonce] + encryptedMessage:[TestUtils encryptedMessage] + nonce:[TestUtils nonce] outDecryptedMessage:&decryptedMessage]; - XCTAssertTrue([decryptedMessage isEqualToData:[SignusUtils message]], @"SignusUtils::decryptWithWalletHandle() failed. Decrypted mesage doesn't match message"); + XCTAssertTrue([decryptedMessage isEqualToData:[TestUtils message]], @"SignusUtils::decryptWithWalletHandle() failed. Decrypted mesage doesn't match message"); [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; @@ -1364,7 +1364,7 @@ - (void)testDecryptWorksForOtherCoder [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -1422,7 +1422,7 @@ - (void)testDecryptWorksForOtherCoder poolHandle:poolHandle myDid:myDid did:myDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:&encryptedMessage outNonce:&nonce]; XCTAssertEqual(ret.code, Success, @"SignusUtils::encryptWithWalletHandle() failed"); @@ -1433,8 +1433,8 @@ - (void)testDecryptWorksForOtherCoder ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:myDid did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] - nonce:[SignusUtils nonce] + encryptedMessage:[TestUtils encryptedMessage] + nonce:[TestUtils nonce] outDecryptedMessage:&decryptedMessage]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code."); @@ -1449,7 +1449,7 @@ - (void)testDecryptWorksForNonceNotCorrespondMessage [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -1461,7 +1461,7 @@ - (void)testDecryptWorksForNonceNotCorrespondMessage // 2. my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -1473,7 +1473,7 @@ - (void)testDecryptWorksForNonceNotCorrespondMessage NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -1491,7 +1491,7 @@ - (void)testDecryptWorksForNonceNotCorrespondMessage ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:myDid did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] + encryptedMessage:[TestUtils encryptedMessage] nonce:[nonce dataUsingEncoding:NSUTF8StringEncoding] outDecryptedMessage:nil]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code."); @@ -1506,7 +1506,7 @@ - (void)testDecryptWorksForInvalidWalletHandle [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -1518,7 +1518,7 @@ - (void)testDecryptWorksForInvalidWalletHandle // 2. my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -1530,7 +1530,7 @@ - (void)testDecryptWorksForInvalidWalletHandle NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -1549,8 +1549,8 @@ - (void)testDecryptWorksForInvalidWalletHandle ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:invalidWalletHandle myDid:myDid did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] - nonce:[SignusUtils nonce] + encryptedMessage:[TestUtils encryptedMessage] + nonce:[TestUtils nonce] outDecryptedMessage:&decryptedMessage]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::decryptWithWalletHandle() returned wrong error code."); diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m index d6a4304285..fffb977c18 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m @@ -142,7 +142,7 @@ -(void)testReplaceKeysWorksForNotExistingDid { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -168,7 +168,7 @@ - (void)testReplaceKeysWorksForCorectCryptoType { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -208,7 +208,7 @@ - (void)testReplaceKeysWorksForInvalidCryptoType { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -317,7 +317,7 @@ - (void)testVerifyWorksForInvalidSignatureLen { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -338,7 +338,7 @@ - (void)testVerifyWorksForInvalidSignatureLen NSString *did; NSString *verKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&did outMyVerkey:&verKey outMyPk:nil]; @@ -357,7 +357,7 @@ - (void)testVerifyWorksForInvalidSignatureLen ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:did - message:[SignusUtils message] + message:[TestUtils message] signature:signature outVerified:&verified]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); @@ -372,7 +372,7 @@ - (void)testVerifyWorksForGetNymFromLedgerWithIncompatibleWallet { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -391,7 +391,7 @@ - (void)testVerifyWorksForGetNymFromLedgerWithIncompatibleWallet // 3. create did NSString *mydid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&mydid outMyVerkey:nil outMyPk:nil]; @@ -408,8 +408,8 @@ - (void)testVerifyWorksForGetNymFromLedgerWithIncompatibleWallet ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:mydid - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:nil]; XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"SignusUtils::verifyWithWalletHandle() returned wrong error code"); @@ -425,7 +425,7 @@ - (void)testVerifyWorksForGetLedgerNotFoundNym { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -464,8 +464,8 @@ - (void)testVerifyWorksForGetLedgerNotFoundNym ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, CommonInvalidState, @"SignusUtils::verifyWithWalletHandle() returned wrong code"); @@ -478,7 +478,7 @@ - (void)testVerifyWorksForGetNymFromLedger { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -497,7 +497,7 @@ - (void)testVerifyWorksForGetNymFromLedger // 3. create & store trustee did NSString *trusteeDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&trusteeDid outMyVerkey:nil outMyPk:nil]; @@ -507,7 +507,7 @@ - (void)testVerifyWorksForGetNymFromLedger NSString *myDid; NSString *myVerKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:&myVerKey outMyPk:nil]; @@ -541,8 +541,8 @@ - (void)testVerifyWorksForGetNymFromLedger ret = [[SignusUtils sharedInstance] verifyWithWalletHandle:walletHandle poolHandle:poolHandle did:myDid - message:[SignusUtils message] - signature:[SignusUtils signature] + message:[TestUtils message] + signature:[TestUtils signature] outVerified:&verified]; XCTAssertEqual(ret.code, Success, @"SignusUtils::verifyWithWalletHandle() failed"); XCTAssertTrue(verified); @@ -560,7 +560,7 @@ - (void)testEncryptWorksForUnknownmyDid [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -598,7 +598,7 @@ - (void)testEncryptWorksForUnknownmyDid poolHandle:poolHandle myDid:@"unknownDid" did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:nil outNonce:nil]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); @@ -614,7 +614,7 @@ - (void)testEncryptWorksForGetNymFromLedgerWithIncompatiblePool [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -661,7 +661,7 @@ - (void)testEncryptWorksForGetNymFromLedgerWithIncompatiblePool poolHandle:poolHandle myDid:myDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:nil outNonce:nil]; XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); @@ -677,7 +677,7 @@ - (void)testEncryptWorksForNotFoundNym [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open pool ledger config, get pool handle IndyHandle poolHandle = 0; @@ -718,7 +718,7 @@ - (void)testEncryptWorksForNotFoundNym poolHandle:poolHandle myDid:myDid did:theirDid - message:[SignusUtils message] + message:[TestUtils message] outEncryptedMessage:nil outNonce:nil]; XCTAssertEqual(ret.code, CommonInvalidState, @"SignusUtils::encryptWithWalletHandle() returned wrong error code"); @@ -736,7 +736,7 @@ - (void)testDecryptWorksForUnknownMyDid [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -749,7 +749,7 @@ - (void)testDecryptWorksForUnknownMyDid NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -766,8 +766,8 @@ - (void)testDecryptWorksForUnknownMyDid ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:@"unknownDid" did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] - nonce:[SignusUtils nonce] + encryptedMessage:[TestUtils encryptedMessage] + nonce:[TestUtils nonce] outDecryptedMessage:nil]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); @@ -781,7 +781,7 @@ - (void)testDecryptworksForUnknownCoderDid [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -793,7 +793,7 @@ - (void)testDecryptworksForUnknownCoderDid // 2. create my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -802,7 +802,7 @@ - (void)testDecryptworksForUnknownCoderDid // 3. create their did NSString *theirDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:nil outMyPk:nil]; @@ -812,8 +812,8 @@ - (void)testDecryptworksForUnknownCoderDid ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:myDid did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] - nonce:[SignusUtils nonce] + encryptedMessage:[TestUtils encryptedMessage] + nonce:[TestUtils nonce] outDecryptedMessage:nil]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); @@ -827,7 +827,7 @@ - (void)testDecryptWorksForSavedCoderNymWithoutPubKey [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -839,7 +839,7 @@ - (void)testDecryptWorksForSavedCoderNymWithoutPubKey // 2. create my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -848,7 +848,7 @@ - (void)testDecryptWorksForSavedCoderNymWithoutPubKey // 3. create their did NSString *theirDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:nil outMyPk:nil]; @@ -865,8 +865,8 @@ - (void)testDecryptWorksForSavedCoderNymWithoutPubKey ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:myDid did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] - nonce:[SignusUtils nonce] + encryptedMessage:[TestUtils encryptedMessage] + nonce:[TestUtils nonce] outDecryptedMessage:nil]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); @@ -880,7 +880,7 @@ -(void)testDecryptWorksForInvalidNonceLen [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = [SignusUtils pool]; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -892,7 +892,7 @@ -(void)testDecryptWorksForInvalidNonceLen // 2. create my did NSString *myDid; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils mySeed] + seed:[TestUtils mySeed] outMyDid:&myDid outMyVerkey:nil outMyPk:nil]; @@ -902,7 +902,7 @@ -(void)testDecryptWorksForInvalidNonceLen NSString *theirDid; NSString *theirVerkey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:[SignusUtils trusteeSeed] + seed:[TestUtils trusteeSeed] outMyDid:&theirDid outMyVerkey:&theirVerkey outMyPk:nil]; @@ -923,7 +923,7 @@ -(void)testDecryptWorksForInvalidNonceLen ret = [[SignusUtils sharedInstance] decryptWithWalletHandle:walletHandle myDid:myDid did:theirDid - encryptedMessage:[SignusUtils encryptedMessage] + encryptedMessage:[TestUtils encryptedMessage] nonce:nonce outDecryptedMessage:nil]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils::decryptWithWalletHandle() returned wrong error code"); diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h index bf07be2485..788ac41458 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/SignusUtils.h @@ -14,16 +14,6 @@ + (SignusUtils *)sharedInstance; -// MARK: - Class variables - -+ (NSString *)pool; -+ (NSData *)message; -+ (NSData *)encryptedMessage; -+ (NSData *)nonce; -+ (NSData *)signature; -+ (NSString *)trusteeSeed; -+ (NSString *)mySeed; - // MARK: - Instance methods - (NSError *)signWithWalletHandle:(IndyHandle)walletHandle diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h index b0d9e7b7a6..e54680e36d 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h @@ -29,4 +29,15 @@ + (void) cleanupStorage; ++ (NSString *)pool; ++ (NSData *)message; ++ (NSData *)encryptedMessage; ++ (NSData *)nonce; ++ (NSData *)signature; ++ (NSString *)trusteeSeed; ++ (NSString *)mySeed; ++ (NSString *)endpoint; ++ (NSString *)clientMessage; ++ (NSString *)serverMessage; + @end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m index 6695147a8b..d751549518 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m @@ -45,4 +45,58 @@ +(NSTimeInterval) longTimeout return 1000; } ++ (NSString *)pool +{ + return @"pool_1"; +} + ++ (NSData *)message +{ + NSString *messageJson = @"{\"reqId\":1496822211362017764}"; + return [messageJson dataUsingEncoding:NSUTF8StringEncoding]; +} + ++ (NSData *)encryptedMessage +{ + const unsigned char bytes[] = {187, 227, 10, 29, 46, 178, 12, 179, 197, 69, 171, 70, 228, 204, 52, 22, 199, 54, 62, 13, 115, 5, 216, 66, 20, 131, 121, 29, 251, 224, 253, 201, 75, 73, 225, 237, 219, 133, 35, 217, 131, 135, 232, 129, 32}; + return [NSData dataWithBytes:bytes length:sizeof(bytes)]; +} + ++ (NSData *)nonce +{ + const unsigned char bytes[] = {242, 246, 53, 153, 106, 37, 185, 65, 212, 14, 109, 131, 200, 169, 94, 110, 51, 47, 101, 89, 0, 171, 105, 183}; + return [NSData dataWithBytes:bytes length:sizeof(bytes)]; +} + ++ (NSData *)signature +{ + const unsigned char bytes[] = {169, 215, 8, 225, 7, 107, 110, 9, 193, 162, 202, 214, 162, 66, 238, 211, 63, 209, 12, 196, 8, 211, 55, 27, 120, 94, 204, 147, 53, 104, 103, 61, 60, 249, 237, 127, 103, 46, 220, 223, 10, 95, 75, 53, 245, 210, 241, 151, 191, 41, 48, 30, 9, 16, 78, 252, 157, 206, 210, 145, 125, 133, 109, 11}; + return [NSData dataWithBytes:bytes length:sizeof(bytes)]; +} + ++ (NSString *)trusteeSeed +{ + return @"000000000000000000000000Trustee1"; +} + ++ (NSString *)mySeed +{ + return @"00000000000000000000000000000My1"; +} + ++ (NSString *)endpoint +{ + return @"127.0.0.1:9700"; +} + ++ (NSString *)clientMessage +{ + return @"msg_from_client"; +} + ++ (NSString *)serverMessage +{ + return @"msg_from_server"; +} + @end From 7e72ea5a3df6764b7a3c485c5c8c62f320f040ac Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Thu, 17 Aug 2017 18:37:44 +0300 Subject: [PATCH 10/29] iOS: added testAgentListenWorksForPassedOnConnectCallback test for agent --- .../Case Tests/Agent/AgentHighCases.m | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m index 27434c673f..36aa852866 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m @@ -471,6 +471,97 @@ - (void)testAgentListenWorksForGetSenderDataFromLedger [TestUtils cleanupStorage]; } +- (void)testAgentListenWorksForPassedOnConnectCallback +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + NSString *msg = @"New Connection"; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. create and open wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + //3. obtain my did + + NSString *did; + NSString *verkey; + NSString *pk; + + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&verkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pk + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 5. listen + + // connection callback + XCTestExpectation* listenerConnectionCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; + __block NSString *connectionCallbackIsCalled; + void (^connectionCallback)(IndyHandle, IndyHandle) = ^(IndyHandle xListenerHandle, IndyHandle xConnectionHandle) { + connectionCallbackIsCalled = msg; + NSLog(@"AgentHighCases::testAgentListenWorksForPassedOnConnectCallback:: listener's connectionCallback triggered."); + [listenerConnectionCompletionExpectation fulfill]; + }; + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:connectionCallback + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 6. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 7. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:nil]; + + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); + + + [self waitForExpectations: @[listenerConnectionCompletionExpectation] timeout:[TestUtils defaultTimeout]]; + XCTAssertTrue([msg isEqualToString:connectionCallbackIsCalled], @"conenction callback is not called!"); + + // 8. close everything + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [TestUtils cleanupStorage]; +} + // MARK: - Add identity - (void)testAgentAddIdentityWorks From ea320c41507bf9e097ea3f7fd20c1ce8cc9bcd00 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 13:53:26 +0300 Subject: [PATCH 11/29] iOS: Added agent connect medium case tests --- libindy/tests/agent.rs | 2 +- .../libindy-demo.xcodeproj/project.pbxproj | 12 + .../Case Tests/Agent/AgentHighCases.m | 106 +- .../Agent/Medium Cases/AgentMediumConnect.m | 1098 +++++++++++++++++ .../libindy-demoTests/Test Utils/AgentUtils.h | 8 +- .../libindy-demoTests/Test Utils/AgentUtils.m | 74 +- .../libindy-demoTests/Test Utils/TestUtils.h | 2 + .../libindy-demoTests/Test Utils/TestUtils.m | 6 +- 8 files changed, 1272 insertions(+), 36 deletions(-) create mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumConnect.m diff --git a/libindy/tests/agent.rs b/libindy/tests/agent.rs index 2f71625715..254a2332d6 100644 --- a/libindy/tests/agent.rs +++ b/libindy/tests/agent.rs @@ -826,7 +826,7 @@ mod medium_cases { })), None).unwrap(); - AgentUtils::add_identity(listener_handle, pool_handle, wallet_handle, did.as_str()).unwrap(); + AgentUtils::add_identity(listener_handle, pool_handle, wallet_handle, did.as_str()).unwrap(); AgentUtils::connect(0, wallet_handle, did.as_str(), did.as_str(), diff --git a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj index 3eb26b1711..5864b2facd 100644 --- a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj +++ b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 5D0481B71F46E1BD00ED79A2 /* AgentMediumConnect.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481B61F46E1BD00ED79A2 /* AgentMediumConnect.m */; }; 5D13F6C61F161E800024DFB3 /* SequenceUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D13F6C51F161E800024DFB3 /* SequenceUtils.m */; }; 5D13F6C81F161E9C0024DFB3 /* libindy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D13F6C71F161E9C0024DFB3 /* libindy.framework */; }; 5D13F6C91F161E9C0024DFB3 /* libindy.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5D13F6C71F161E9C0024DFB3 /* libindy.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -90,6 +91,7 @@ 2EF9598E5D9881BADD8E4EB7 /* Pods-libindy-demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libindy-demo.release.xcconfig"; path = "Pods/Target Support Files/Pods-libindy-demo/Pods-libindy-demo.release.xcconfig"; sourceTree = ""; }; 3E2A7F851EC36186006194EC /* libindy-demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "libindy-demo.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 3E2A7F9E1EC36187006194EC /* libindy-demoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "libindy-demoTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 5D0481B61F46E1BD00ED79A2 /* AgentMediumConnect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumConnect.m; sourceTree = ""; }; 5D13F6C41F161E800024DFB3 /* SequenceUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SequenceUtils.h; sourceTree = ""; }; 5D13F6C51F161E800024DFB3 /* SequenceUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequenceUtils.m; sourceTree = ""; }; 5D13F6C71F161E9C0024DFB3 /* libindy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = libindy.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -196,6 +198,14 @@ name = Products; sourceTree = ""; }; + 5D0481B41F46E16B00ED79A2 /* Medium Cases */ = { + isa = PBXGroup; + children = ( + 5D0481B61F46E1BD00ED79A2 /* AgentMediumConnect.m */, + ); + path = "Medium Cases"; + sourceTree = ""; + }; 5DF013D01F1604C100076592 /* libindy-demo */ = { isa = PBXGroup; children = ( @@ -241,6 +251,7 @@ 5DF014681F1605EB00076592 /* Agent */ = { isa = PBXGroup; children = ( + 5D0481B41F46E16B00ED79A2 /* Medium Cases */, 5DF014691F1605EB00076592 /* AgentHighCases.m */, 5DF0146A1F1605EB00076592 /* AgentMediumCases.m */, ); @@ -593,6 +604,7 @@ 5DF014B91F1605EB00076592 /* TestUtils.m in Sources */, 5DF014A31F1605EB00076592 /* LedgerAttribRequest.mm in Sources */, 5DF014A21F1605EB00076592 /* AnoncredsMediumCasesDemos.m in Sources */, + 5D0481B71F46E1BD00ED79A2 /* AgentMediumConnect.m in Sources */, 5DF014B61F1605EB00076592 /* LedgerUtils.mm in Sources */, 5DF014AD1F1605EB00076592 /* WalletMediumCases.m in Sources */, 5DF014A81F1605EB00076592 /* PoolHighCases.m in Sources */, diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m index 36aa852866..28d6c3d35c 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m @@ -497,20 +497,20 @@ - (void)testAgentListenWorksForPassedOnConnectCallback NSString *did; NSString *verkey; - NSString *pk; + NSString *pubKey; ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle seed:nil outMyDid:&did outMyVerkey:&verkey - outMyPk:&verkey]; + outMyPk:&pubKey]; XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); // 4. store their did from parts ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle theirDid:did - theirPk:pk + theirPk:pubKey theirVerkey:verkey endpoint:[TestUtils endpoint]]; XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); @@ -562,6 +562,106 @@ - (void)testAgentListenWorksForPassedOnConnectCallback [TestUtils cleanupStorage]; } +- (void)testAgentListenWorksForPassedOnMessageCallback +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + NSString *msg = @"Message from client"; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. create and open wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + //3. obtain my did + + NSString *did; + NSString *verkey; + NSString *pubKey; + + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubKey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 5. listen + + XCTestExpectation* messageFromClientCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; + __block NSString *clientMessage; + // message from client callback + void (^messageFromClientCallback)(IndyHandle, NSString *) = ^(IndyHandle xConnectionHandle, NSString * message) { + clientMessage = message; + NSLog(@"AgentHighCases::testAgentSendWorksForAllDataInWalletPresent::messageFromClientCallback triggered with message: %@", message); + [messageFromClientCompletionExpectation fulfill]; + }; + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:messageFromClientCallback + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 6. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 7. connect + IndyHandle connectionHandle = 0; + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:&connectionHandle]; + + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); + + // 8. send message + + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandle + message:msg]; + XCTAssertEqual(ret.code,Success, @"AgentUtils::sendWithConnectionHandler failed"); + + [self waitForExpectations: @[messageFromClientCompletionExpectation] timeout:[TestUtils defaultTimeout]]; + XCTAssertTrue([clientMessage isEqualToString:msg], @"wrong clientMessage"); + + + // 8. close everything + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[AgentUtils sharedInstance] closeListener:connectionHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [TestUtils cleanupStorage]; +} + + // MARK: - Add identity - (void)testAgentAddIdentityWorks diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumConnect.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumConnect.m new file mode 100644 index 0000000000..71d2ba2f87 --- /dev/null +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumConnect.m @@ -0,0 +1,1098 @@ +// +// AgentMediumConnect.m +// libindy-demo +// +// Created by Anastasia Tarasova on 18/08/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + + +#import +#import +#import +#import "TestUtils.h" + +@interface AgentMediumConnect : XCTestCase + +@end + +@implementation AgentMediumConnect +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +// MARK: - Connect + +- (void)testAgentConnectWorksForUnknownListener +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. listener wallet + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for listener wallet"); + + // 3. sender wallet + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for sender wallet"); + + // 4. obtain listener did + + NSString *listenerDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed listener did"); + + // 5. obtain sender did + + NSString *senderDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:nil + outMyDid:&senderDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed sender did"); + + // 6. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 7. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 8. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::connectWithPoolHandle() returned wrong error code"); + + // 9. close everything + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForInvalidRemoteData +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. listener wallet + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for listener wallet"); + + // 3. trustee wallet + IndyHandle trusteeWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&trusteeWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for trustee wallet"); + IndyHandle senderWallet = trusteeWallet; + + // 4. obtain listener did + + NSString *listenerDid; + NSString *listenerVerKey; + NSString *listenerPubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerKey + outMyPk:&listenerPubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed listener did"); + + // 5. obtain trustee did + + NSString *trusteeDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:trusteeWallet + seed:[TestUtils trusteeSeed] + outMyDid:&trusteeDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed trustee did"); + + NSString *senderDid = [NSString stringWithString:trusteeDid]; + + // 6. Build & submit nym request + + NSString *listenerNymJson; + ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid + targetDid:listenerDid + verkey:listenerVerKey + alias:nil + role:nil + outRequest:&listenerNymJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildNymRequestWithSubmitterDid() failed"); + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:trusteeWallet + submitterDid:trusteeDid + requestJson:listenerNymJson + outResponseJson:nil]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for listenerNymJson"); + + // 7. Build & submit attrib request + + NSString *invalidAttribData = [NSString stringWithFormat:@"{\"endpoint\":{\"verkey\":\"%@\"}}", listenerPubKey]; + NSString *listenerAttribJson; + ret = [[LedgerUtils sharedInstance] buildAttribRequestWithSubmitterDid:listenerDid + targetDid:listenerDid + hash:nil + raw:invalidAttribData + enc:nil + resultJson:&listenerAttribJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildAttribRequestWithSubmitterDid() failed"); + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:listenerWallet + submitterDid:listenerDid + requestJson:listenerAttribJson + outResponseJson:nil]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for listenerAttribJson"); + + // 8. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 9. add identity + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 10. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::connectWithPoolHandle() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForExpiredKeyInWallet +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. listener wallet + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for listener wallet"); + + // 3. sender wallet + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for sender wallet"); + + // 4. obtain listener did + + NSString *listenerDid; + NSString *listenerVerKey; + NSString *listenerPubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerKey + outMyPk:&listenerPubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed listener did"); + + // 5. obtain trustee did + + NSString *senderDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:[TestUtils trusteeSeed] + outMyDid:&senderDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed sender did"); + + // 6. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:senderWallet + theirDid:listenerDid + theirPk:listenerPubKey + theirVerkey:listenerVerKey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 7. replace keys + + NSString *listenerNewVerKey; + NSString *listenerNewPubKey; + + ret = [[SignusUtils sharedInstance] replaceKeysWithWalletHandle:listenerWallet + did:listenerDid + identityJson:@"{}" + outMyVerKey:&listenerNewVerKey + outMyPk:&listenerNewPubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::replaceKeysWithWalletHandle() failed"); + + XCTAssertFalse([listenerVerKey isEqualToString:listenerNewVerKey], @"listener's verKey is the same!"); + XCTAssertFalse([listenerPubKey isEqualToString:listenerNewPubKey], @"listener's pub key is the same!"); + + // 8. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 9. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 10. connect hang up expected + + BOOL isTimeout = NO; + ret = [[AgentUtils sharedInstance] connectHangUpExpectedForPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + isTimeout:&isTimeout]; + XCTAssertEqual(isTimeout, YES, @"AgentUtils::connectHandUpExpectedForPoolHandle() succeeded for some reason"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForExpiredKeyInLedger +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. listener wallet + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for listener wallet"); + + // 3. trustee wallet + IndyHandle trusteeWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&trusteeWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for trustee wallet"); + IndyHandle senderWallet = trusteeWallet; + + // 4. obtain listener did + + NSString *listenerDid; + NSString *listenerVerKey; + NSString *listenerPubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerKey + outMyPk:&listenerPubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed listener did"); + + // 5. obtain trustee did + + NSString *trusteeDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:trusteeWallet + seed:[TestUtils trusteeSeed] + outMyDid:&trusteeDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed trustee did"); + + NSString *senderDid = [NSString stringWithString:trusteeDid]; + + // 6. Build & submit nym request + + NSString *listenerNymJson; + ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid + targetDid:listenerDid + verkey:listenerVerKey + alias:nil + role:nil + outRequest:&listenerNymJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildNymRequestWithSubmitterDid() failed"); + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:trusteeWallet + submitterDid:trusteeDid + requestJson:listenerNymJson + outResponseJson:nil]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for listenerNymJson"); + + // 7. Build & submit attrib request + + NSString *invalidAttribData = [NSString stringWithFormat:@"{\"endpoint\":{\"ha\":\"%@\", \"verkey\":\"%@\"}}", [TestUtils endpoint], listenerPubKey]; + NSString *listenerAttribJson; + ret = [[LedgerUtils sharedInstance] buildAttribRequestWithSubmitterDid:listenerDid + targetDid:listenerDid + hash:nil + raw:invalidAttribData + enc:nil + resultJson:&listenerAttribJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildAttribRequestWithSubmitterDid() failed"); + + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:listenerWallet + submitterDid:listenerDid + requestJson:listenerAttribJson + outResponseJson:nil]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for listenerAttribJson"); + + // 8. replace keys + + NSString *listenerNewVerKey; + NSString *listenerNewPubKey; + + ret = [[SignusUtils sharedInstance] replaceKeysWithWalletHandle:listenerWallet + did:listenerDid + identityJson:@"{}" + outMyVerKey:&listenerNewVerKey + outMyPk:&listenerNewPubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::replaceKeysWithWalletHandle() failed"); + + XCTAssertFalse([listenerVerKey isEqualToString:listenerNewVerKey], @"listener's verKey is the same!"); + XCTAssertFalse([listenerPubKey isEqualToString:listenerNewPubKey], @"listener's pub key is the same!"); + + // 9. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 9. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 10. connect hang up expected + + BOOL isTimeout = NO; + ret = [[AgentUtils sharedInstance] connectHangUpExpectedForPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + isTimeout:&isTimeout]; + XCTAssertEqual(isTimeout, YES, @"AgentUtils::connectHandUpExpectedForPoolHandle() succeeded for some reason"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForIncompatibleWalletAndPool +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"other_pool" + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 3. obtain my did + + NSString *did; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 5. add identity + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 6. connect + + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, WalletIncompatiblePoolError, @"AgentUtils::connectWithPoolHandle() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForUnknownSenderDid +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. create and open pool ledger + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 3. obtain my did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 5. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 6. add identity + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 7. connect + + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:walletHandle + senderDid:@"unknownDid" + receiverDid:did + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, WalletNotFoundError, @"AgentUtils::connectWithPoolHandle() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentconnectWorksForInvalidListener +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain my did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 3. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 4. connect hang up expected + + BOOL isTimeout = NO; + ret = [[AgentUtils sharedInstance] connectHangUpExpectedForPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + isTimeout:&isTimeout]; + XCTAssertTrue(isTimeout, @"AgentUtils::connectHandUpExpectedForPoolHandle() succeeded for some reason"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForClosedListener +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain my did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 3. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 4. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 5. add identity + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 6. close listener + + ret = [[AgentUtils sharedInstance] closeListener:listenerHandle]; + + // 7. connect hang up expected + + BOOL isTimeout = NO; + ret = [[AgentUtils sharedInstance] connectHangUpExpectedForPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + isTimeout:&isTimeout]; + XCTAssertTrue(isTimeout, @"AgentUtils::connectHandUpExpectedForPoolHandle() succeeded for some reason"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForConnectWithoutAddIdentity +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain my did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 3. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 4. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 5. connect hang up expected + + BOOL isTimeout = NO; + ret = [[AgentUtils sharedInstance] connectHangUpExpectedForPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + isTimeout:&isTimeout]; + XCTAssertTrue(isTimeout, @"AgentUtils::connectHandUpExpectedForPoolHandle() succeeded for some reason"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForConnectAfterRemoveIdentity +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain my did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 3. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 4. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 5. add identity + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 6. remove identity + + ret = [[AgentUtils sharedInstance] removeIdentity:did + listenerHandle:listenerHandle + walletHandle:walletHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::removeIdentity() failed"); + + // 7. connect hang up expected + + BOOL isTimeout = NO; + ret = [[AgentUtils sharedInstance] connectHangUpExpectedForPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + isTimeout:&isTimeout]; + XCTAssertTrue(isTimeout, @"AgentUtils::connectHandUpExpectedForPoolHandle() succeeded for some reason"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForPassedCallback +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. pool handle + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. wallet + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 3. obtain my did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 5. listen + + // connection callback + XCTestExpectation* listenerConnectionCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; + __block IndyHandle connectionHandleFromCallback; + void (^connectionCallback)(IndyHandle, IndyHandle) = ^(IndyHandle xListenerHandle, IndyHandle xConnectionHandle) { + NSLog(@"AgentHighCases::testAgentListenWorksForPassedOnConnectCallback:: listener's connectionCallback triggered."); + connectionHandleFromCallback = xConnectionHandle; + [listenerConnectionCompletionExpectation fulfill]; + }; + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:connectionCallback + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 6. add identity + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 7. connect + + // message from server callback + + XCTestExpectation* messageFromClientCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; + __block NSString *clientMessage; + void (^messageFromClientCallback)(IndyHandle, NSString *) = ^(IndyHandle xConnectionHandle, NSString * message) { + clientMessage = message; + NSLog(@"messageFromClientCallback triggered with message: %@", message); + [messageFromClientCompletionExpectation fulfill]; + }; + + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:messageFromClientCallback + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); + + [self waitForExpectations:@[listenerConnectionCompletionExpectation] timeout:[TestUtils defaultTimeout]]; + + // 8. send + + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandleFromCallback + message:[TestUtils clientMessage]]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::sendWithConnectionHandler() failed"); + + [self waitForExpectations: @[messageFromClientCompletionExpectation] timeout:[TestUtils defaultTimeout]]; + XCTAssertTrue([clientMessage isEqualToString:[TestUtils clientMessage]], @"wrong client message"); + + // 9. clean + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [[PoolUtils sharedInstance] closeHandle: poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentConnectWorksForTwice +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. pool handle + + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. listener wallet + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for listener wallet"); + + // 3. sender wallet + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed for sender wallet"); + + // 4. obtain listener did + + NSString *listenerDid; + NSString *listenerVerkey; + NSString *listenerPubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerkey + outMyPk:&listenerPubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for listener did"); + + // 5. obtain sender did + + NSString *senderDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:[TestUtils trusteeSeed] + outMyDid:&senderDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for sender did"); + + // 6. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:senderWallet + theirDid:listenerDid + theirPk:listenerPubkey + theirVerkey:listenerVerkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 7. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 8. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 9. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); + + // 10. connect hang up expected + BOOL isTimeout = NO; + ret = [[AgentUtils sharedInstance] connectHangUpExpectedForPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + isTimeout:&isTimeout]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectHandUpExpectedForPoolHandle() failed"); + + // 11. close + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + + + +@end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.h index bc21354adb..0c7a77d535 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.h @@ -38,8 +38,14 @@ walletHandle:(IndyHandle)walletHandle did:(NSString *)did; -- (NSError *)removeIdentity:(NSString *) did +- (NSError *)removeIdentity:(NSString *)did listenerHandle:(IndyHandle)listenerHandle walletHandle:(IndyHandle)walletHandle; +- (NSError *)connectHangUpExpectedForPoolHandle:(IndyHandle)poolHandle + walletHandle:(IndyHandle)walletHandle + senderDid:(NSString *)senderDid + receiverDid:(NSString *)receiverDid + isTimeout:(BOOL *)isTimeout; + @end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.m b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.m index b60efba3fd..20a4722ab9 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AgentUtils.m @@ -94,34 +94,6 @@ - (NSError *)listenForEndpoint:(NSString *)endpoint messageCallback:(void (^)(IndyHandle connectionHandle, NSString *message))messageCallback outListenerHandle:(IndyHandle *)listenerHandle { - - #if 0 - // connection callback - void (^onConnectCallback)(IndyHandle, NSError*, IndyHandle, NSString*, NSString* ) = ^(IndyHandle xListenerHandle, NSError *error, IndyHandle connectionHandle, NSString *senderDid, NSString *receiverDid) { - NSLog(@"AgentUtils::listen::New connection %d on listener %d, err %ld, sender DID %@, receiver DID: %@", (int)connectionHandle, (int)xListenerHandle, (long)error.code, senderDid, receiverDid); - if (connectionCallback) {connectionCallback(xListenerHandle, connectionHandle);} - }; - - - // listener callback. We need to obtain listenerHandle, so we wait for completion. Connection and message callnacks can be triggered multiple times later, so we just pass them to register. - XCTestExpectation* listenerCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; - __block IndyHandle tempListenerHandle = 0; - __block NSError *listenerErr; - - void (^onListenerCallback)(NSError*, IndyHandle) = ^(NSError *error, IndyHandle xListenerHandle) { - NSLog(@"OnListenerCallback triggered."); - listenerErr = error; - tempListenerHandle = xListenerHandle; - [listenerCompletionExpectation fulfill]; - }; - - // message callback - void (^onMessageCallback)(IndyHandle, NSError*, NSString*) = ^(IndyHandle xConnectionHandle, NSError *error, NSString *message) { - NSLog(@"AgentUtils::listen::On connection %d received (with error %ld) agent message (CLI->SRV): %@", (int)xConnectionHandle, (long)error.code, message); - if (messageCallback != nil) { messageCallback(xConnectionHandle, message);} - }; -#endif - // listener callback. We need to obtain listenerHandle, so we wait for completion. Connection and message callnacks can be triggered multiple times later, so we just pass them to register. XCTestExpectation* listenerCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; __block IndyHandle tempListenerHandle = 0; @@ -288,5 +260,51 @@ - (NSError *)removeIdentity:(NSString *) did return err; } +- (NSError *)connectHangUpExpectedForPoolHandle:(IndyHandle)poolHandle + walletHandle:(IndyHandle)walletHandle + senderDid:(NSString *)senderDid + receiverDid:(NSString *)receiverDid + isTimeout:(BOOL *)isTimeout +{ + // connection callback. waiting for completion + XCTestExpectation* connectCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; + __block NSError *connectionErr; + __block IndyHandle tempConnectionHandle; + + void (^onConnectCallback)(NSError*, IndyHandle) = ^(NSError *error, IndyHandle connectionHandle) { + NSLog(@"AgentUtils::connectWithPoolHandle::OnConnectCallback triggered with code: %ld", (long)error.code); + tempConnectionHandle = connectionHandle; + connectionErr = error; + [connectCompletionExpectation fulfill]; + }; + + __weak typeof(self)weakSelf = self; + weakSelf.connectionCallbacks[@(tempConnectionHandle)] = ^(IndyHandle xConnectionHandle, NSError *error, NSString *message) { + NSLog(@"AgentUtils::connectWithPoolHandle::OnMessageCallback triggered invoced with error code: %ld", (long)error.code); + }; + + NSError *ret = [IndyAgent connectWithPoolHandle:poolHandle + walletHandle:walletHandle + senderDId:senderDid + receiverDId:receiverDid + connectionHandler:onConnectCallback + messageHandler:(void (^)(IndyHandle, NSError*, NSString*))weakSelf.connectionCallbacks[@(tempConnectionHandle)]]; + + if (ret.code != Success) + { + return ret; + } + + // wait for connection callback + [self waitForExpectations: @[connectCompletionExpectation] timeout:[TestUtils shortTimeout]]; + + if (connectionErr) + { + return connectionErr; + } else { + if (isTimeout) { *isTimeout = YES; } + return ret; + } +} @end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h index e54680e36d..9cdb02a568 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.h @@ -40,4 +40,6 @@ + (NSString *)clientMessage; + (NSString *)serverMessage; + + @end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m index d751549518..13533c2e8f 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/TestUtils.m @@ -32,17 +32,17 @@ +(void) cleanupStorage +(NSTimeInterval) defaultTimeout { - return 1000; + return 10; } +(NSTimeInterval) shortTimeout { - return 1000; + return 5; } +(NSTimeInterval) longTimeout { - return 1000; + return 100; } + (NSString *)pool From 9e9d16084ff5637735afa68a3b80fd9ff94612e3 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 14:39:23 +0300 Subject: [PATCH 12/29] iOS: Added agent listen medium cases tests --- .../libindy-demo.xcodeproj/project.pbxproj | 24 ++ .../Medium Cases/AgentMediumAddIdentity.m | 9 + .../Medium Cases/AgentMediumCloseConnection.m | 9 + .../Medium Cases/AgentMediumCloseListener.m | 9 + .../Agent/Medium Cases/AgentMediumListen.m | 271 ++++++++++++++++++ .../Medium Cases/AgentMediumRemoveIdentity.m | 9 + .../Agent/Medium Cases/AgentMediumSend.m | 9 + 7 files changed, 340 insertions(+) create mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m create mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m create mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m create mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m create mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m create mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m diff --git a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj index 5864b2facd..22485def96 100644 --- a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj +++ b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj @@ -8,6 +8,12 @@ /* Begin PBXBuildFile section */ 5D0481B71F46E1BD00ED79A2 /* AgentMediumConnect.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481B61F46E1BD00ED79A2 /* AgentMediumConnect.m */; }; + 5D0481B91F46FEC800ED79A2 /* AgentMediumListen.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481B81F46FEC800ED79A2 /* AgentMediumListen.m */; }; + 5D0481BB1F46FEE400ED79A2 /* AgentMediumAddIdentity.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481BA1F46FEE400ED79A2 /* AgentMediumAddIdentity.m */; }; + 5D0481BD1F46FEFA00ED79A2 /* AgentMediumRemoveIdentity.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481BC1F46FEFA00ED79A2 /* AgentMediumRemoveIdentity.m */; }; + 5D0481BF1F46FF0D00ED79A2 /* AgentMediumSend.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481BE1F46FF0D00ED79A2 /* AgentMediumSend.m */; }; + 5D0481C11F46FF2700ED79A2 /* AgentMediumCloseConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481C01F46FF2700ED79A2 /* AgentMediumCloseConnection.m */; }; + 5D0481C31F46FF4000ED79A2 /* AgentMediumCloseListener.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D0481C21F46FF4000ED79A2 /* AgentMediumCloseListener.m */; }; 5D13F6C61F161E800024DFB3 /* SequenceUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D13F6C51F161E800024DFB3 /* SequenceUtils.m */; }; 5D13F6C81F161E9C0024DFB3 /* libindy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D13F6C71F161E9C0024DFB3 /* libindy.framework */; }; 5D13F6C91F161E9C0024DFB3 /* libindy.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5D13F6C71F161E9C0024DFB3 /* libindy.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -92,6 +98,12 @@ 3E2A7F851EC36186006194EC /* libindy-demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "libindy-demo.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 3E2A7F9E1EC36187006194EC /* libindy-demoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "libindy-demoTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 5D0481B61F46E1BD00ED79A2 /* AgentMediumConnect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumConnect.m; sourceTree = ""; }; + 5D0481B81F46FEC800ED79A2 /* AgentMediumListen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumListen.m; sourceTree = ""; }; + 5D0481BA1F46FEE400ED79A2 /* AgentMediumAddIdentity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumAddIdentity.m; sourceTree = ""; }; + 5D0481BC1F46FEFA00ED79A2 /* AgentMediumRemoveIdentity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumRemoveIdentity.m; sourceTree = ""; }; + 5D0481BE1F46FF0D00ED79A2 /* AgentMediumSend.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumSend.m; sourceTree = ""; }; + 5D0481C01F46FF2700ED79A2 /* AgentMediumCloseConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumCloseConnection.m; sourceTree = ""; }; + 5D0481C21F46FF4000ED79A2 /* AgentMediumCloseListener.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumCloseListener.m; sourceTree = ""; }; 5D13F6C41F161E800024DFB3 /* SequenceUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SequenceUtils.h; sourceTree = ""; }; 5D13F6C51F161E800024DFB3 /* SequenceUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SequenceUtils.m; sourceTree = ""; }; 5D13F6C71F161E9C0024DFB3 /* libindy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = libindy.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -202,6 +214,12 @@ isa = PBXGroup; children = ( 5D0481B61F46E1BD00ED79A2 /* AgentMediumConnect.m */, + 5D0481B81F46FEC800ED79A2 /* AgentMediumListen.m */, + 5D0481BA1F46FEE400ED79A2 /* AgentMediumAddIdentity.m */, + 5D0481BC1F46FEFA00ED79A2 /* AgentMediumRemoveIdentity.m */, + 5D0481BE1F46FF0D00ED79A2 /* AgentMediumSend.m */, + 5D0481C01F46FF2700ED79A2 /* AgentMediumCloseConnection.m */, + 5D0481C21F46FF4000ED79A2 /* AgentMediumCloseListener.m */, ); path = "Medium Cases"; sourceTree = ""; @@ -602,8 +620,10 @@ 5DF014B41F1605EB00076592 /* ClosureUtils.m in Sources */, 5DF0149F1F1605EB00076592 /* AgentMediumCases.m in Sources */, 5DF014B91F1605EB00076592 /* TestUtils.m in Sources */, + 5D0481C31F46FF4000ED79A2 /* AgentMediumCloseListener.m in Sources */, 5DF014A31F1605EB00076592 /* LedgerAttribRequest.mm in Sources */, 5DF014A21F1605EB00076592 /* AnoncredsMediumCasesDemos.m in Sources */, + 5D0481C11F46FF2700ED79A2 /* AgentMediumCloseConnection.m in Sources */, 5D0481B71F46E1BD00ED79A2 /* AgentMediumConnect.m in Sources */, 5DF014B61F1605EB00076592 /* LedgerUtils.mm in Sources */, 5DF014AD1F1605EB00076592 /* WalletMediumCases.m in Sources */, @@ -622,8 +642,12 @@ 5DF014AF1F1605EB00076592 /* LedgerDemo.mm in Sources */, 5DF014B21F1605EB00076592 /* AgentUtils.m in Sources */, 5DF014AB1F1605EB00076592 /* SignusMediumCases.m in Sources */, + 5D0481BD1F46FEFA00ED79A2 /* AgentMediumRemoveIdentity.m in Sources */, 5DF014BC1F1605EB00076592 /* NSDictionary+JSON.m in Sources */, + 5D0481BB1F46FEE400ED79A2 /* AgentMediumAddIdentity.m in Sources */, 5DF014A11F1605EB00076592 /* AnoncredsMediumCases.m in Sources */, + 5D0481B91F46FEC800ED79A2 /* AgentMediumListen.m in Sources */, + 5D0481BF1F46FF0D00ED79A2 /* AgentMediumSend.m in Sources */, 5DF014A61F1605EB00076592 /* LedgerNymRequest.mm in Sources */, 5DF014BD1F1605EB00076592 /* NSString+Validation.m in Sources */, 5DF014BA1F1605EB00076592 /* WalletUtils.m in Sources */, diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m new file mode 100644 index 0000000000..3468f16f1d --- /dev/null +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m @@ -0,0 +1,9 @@ +// +// AgentMediumAddIdentity.m +// libindy-demo +// +// Created by Anastasia Tarasova on 18/08/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + +#import diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m new file mode 100644 index 0000000000..be73e3532b --- /dev/null +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m @@ -0,0 +1,9 @@ +// +// AgentMediumCloseConnection.m +// libindy-demo +// +// Created by Anastasia Tarasova on 18/08/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + +#import diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m new file mode 100644 index 0000000000..d44e04f6fc --- /dev/null +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m @@ -0,0 +1,9 @@ +// +// AgentMediumCloseListener.m +// libindy-demo +// +// Created by Anastasia Tarasova on 18/08/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + +#import diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m new file mode 100644 index 0000000000..997c12560a --- /dev/null +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m @@ -0,0 +1,271 @@ +// +// AgentMediumListen.m +// libindy-demo +// +// Created by Anastasia Tarasova on 18/08/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + +#import + +#import +#import +#import +#import "TestUtils.h" + +@interface AgentMediumListen : XCTestCase + +@end + +@implementation AgentMediumListen + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testAgentListenWorksForEndpointAlreadyInUse +{ + [TestUtils cleanupStorage]; + NSError *ret; + + // 1. listen first + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint failed"); + + // 2. listen second + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:nil]; + XCTAssertEqual(ret.code, CommonIOError, @"AgentUtils::listenForEndpoint returned wrong error code"); + + // 3. close listener + ret = [[AgentUtils sharedInstance] closeListener:listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::closeListener failed"); + + [TestUtils cleanupStorage]; +} + +- (void)testAgentListenWorksForInvalidEndpoint +{ + [TestUtils cleanupStorage]; + NSError *ret; + + ret = [[AgentUtils sharedInstance] listenForEndpoint:@"127.0.0" + connectionCallback:nil + messageCallback:nil + outListenerHandle:nil]; + XCTAssertEqual(ret.code, CommonIOError, @"AgentUtils::listenForEndpoint returned wrong error code"); + + [TestUtils cleanupStorage]; +} + +- (void)testAgentListenWorksForRejectUnknownSender +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. pool + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName failed"); + + // 2. listener handle + + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for listenerWallet"); + + // 3. sender wallet + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for senderWallet"); + + // 4. obtain listener did + NSString *listenerDid; + NSString *listenerVerkey; + NSString *listenerPubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerkey + outMyPk:&listenerPubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for listenerDid"); + + // 5. obtain sender did + NSString *senderDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:nil + outMyDid:&senderDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for senderDid"); + + // 6. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:senderWallet + theirDid:listenerDid + theirPk:listenerPubkey + theirVerkey:listenerVerkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle failed"); + + // 7. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint failed"); + + // 8. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle failed"); + + // 9. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, CommonInvalidState, @"AgentUtils::connectWithPoolHandle returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentListenWorksForRejectExpiredSavedSenderData +{ + [TestUtils cleanupStorage]; + + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. pool + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName failed"); + + // 2. listener handle + + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for listenerWallet"); + + // 3. sender wallet + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for senderWallet"); + + // 4. obtain listener did + NSString *listenerDid; + NSString *listenerVerkey; + NSString *listenerPubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:[TestUtils trusteeSeed] + outMyDid:&listenerDid + outMyVerkey:&listenerVerkey + outMyPk:&listenerPubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for listenerDid"); + + // 5. obtain sender did + NSString *senderDid; + NSString *senderVerkey; + NSString *senderPubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:nil + outMyDid:&senderDid + outMyVerkey:&senderVerkey + outMyPk:&senderPubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for senderDid"); + + // 6. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:listenerWallet + theirDid:senderDid + theirPk:senderPubkey + theirVerkey:senderVerkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle failed"); + + // 7. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint failed"); + + // 8. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle failed"); + + // 9. replace keys + ret = [[SignusUtils sharedInstance] replaceKeysWithWalletHandle:senderWallet + did:senderDid + identityJson:@"{}" + outMyVerKey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::replaceKeysWithWalletHandle failed"); + + // 10. store their did from parts + + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:senderWallet + theirDid:listenerDid + theirPk:listenerPubkey + theirVerkey:listenerVerkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle failed"); + + // 11. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, CommonInvalidState, @"AgentUtils::connectWithPoolHandle returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + + [TestUtils cleanupStorage]; +} + +@end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m new file mode 100644 index 0000000000..f356ecf837 --- /dev/null +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m @@ -0,0 +1,9 @@ +// +// AgentMediumRemoveIdentity.m +// libindy-demo +// +// Created by Anastasia Tarasova on 18/08/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + +#import diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m new file mode 100644 index 0000000000..81bd61470f --- /dev/null +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m @@ -0,0 +1,9 @@ +// +// AgentMediumSend.m +// libindy-demo +// +// Created by Anastasia Tarasova on 18/08/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + +#import From a996d51ea67d8dcdd7f2cfce7523b13bec30ec2a Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 15:41:10 +0300 Subject: [PATCH 13/29] iOS: Added agent remove identity medium tests --- .../Medium Cases/AgentMediumAddIdentity.m | 443 ++++++++++++++++++ .../Agent/Medium Cases/AgentMediumListen.m | 2 - .../Medium Cases/AgentMediumRemoveIdentity.m | 228 +++++++++ 3 files changed, 671 insertions(+), 2 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m index 3468f16f1d..733bbf4a8f 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumAddIdentity.m @@ -7,3 +7,446 @@ // #import +#import +#import +#import "TestUtils.h" + +@interface AgentMediumAddIdentity : XCTestCase + +@end + +@implementation AgentMediumAddIdentity + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testAgentAddIdentityWorksForIncomingConnectionRequireLedgerRequestButPoolHandleIsInvalid +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = @"indy_agent_add_identity_works_for_incoming_connection_require_ledger_request_but_pool_handle_is_invalid"; + + // 1. Obtain pool handle + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); + + // 2. Obtain listener's wallet + IndyHandle listenerWalletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWalletHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenWalletWithPoolName() failed"); + + // 3. Obtain trustee's wallet + IndyHandle trusteeWalletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&trusteeWalletHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenWalletWithPoolName() failed"); + + // 4. Create and store listener's did + NSString *listenerDid; + NSString *listenerVerKey; + NSString *listenerPubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWalletHandle + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerKey + outMyPk:&listenerPubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for listener"); + + // 5. create trustee did + + NSString *trusteeDid; + ret =[[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:trusteeWalletHandle + seed:[TestUtils trusteeSeed] + outMyDid:&trusteeDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); + NSString *senderDid = [NSString stringWithString:trusteeDid]; + IndyHandle senderWallet = trusteeWalletHandle; + + // 6. Build nym request for listener + NSString *listenerNymRequest; + ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid + targetDid:listenerDid + verkey:listenerVerKey + alias:nil + role:nil + outRequest:&listenerNymRequest]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildNymRequestWithSubmitterDid() failed"); + + // 7. Sign and submit listener's nym request + NSString *listenerNymResponse; + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:trusteeWalletHandle + submitterDid:trusteeDid + requestJson:listenerNymRequest + outResponseJson:&listenerNymResponse]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for listenerNymRequest"); + + // 8. Build listener attribute request + NSString *rawJson =[NSString stringWithFormat:@"{\"endpoint\":{\"ha\":\"%@\", \"verkey\":\"%@\"}}", [TestUtils endpoint], listenerPubKey]; + NSString *listenerAttributeRequest; + ret = [[LedgerUtils sharedInstance] buildAttribRequestWithSubmitterDid:listenerDid + targetDid:listenerDid + hash:nil + raw:rawJson + enc:nil + resultJson:&listenerAttributeRequest]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildAttribRequestWithSubmitterDid() failed"); + + // 9. Sign and submit listener's attribute request + NSString *listenerAttributeResponse; + ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle + walletHandle:listenerWalletHandle + submitterDid:listenerDid + requestJson:listenerAttributeRequest + outResponseJson:&listenerAttributeResponse]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildAttribRequestWithSubmitterDid() failed for listenerAttributeResponse"); + + // 10. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::listenWithEndpoint()"); + + // 11. Add identity + IndyHandle invalidPoolHandle = listenerHandle; + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:invalidPoolHandle + walletHandle:listenerWalletHandle + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::addIdentityForListenerHandle() failed for listenerDid"); + + /* TODO + * Currently pool_handle and wallet_handle of add_identity will be checked only at required: + * when listener will check incoming connection and go to ledger for info. + * As result, add_identity will be successful but next connect will fail. + * Possible the test should be split into two: + * - add_identity_works_for_incompatible_pool_and_wallet + * with immediately check in the library + * - connect_works_for_incorrect_connect_request + * actual info in ledger or listener_wallet, wrong public key in sender_wallet + */ + + // 12. Connect + + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, CommonInvalidState, @"AgentUtils::connectWithPoolHandle() returned wrong code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWalletHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle: poolHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentAddIdentityWorksForUnknownDid +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:1 + walletHandle:walletHandle + did:@"unknownDid"]; + XCTAssertEqual(ret.code, WalletNotFoundError, @"AgentUtils::addIdentityForListenerHandle() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentAddIdentityWorksForInvalidListenerHandle +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain receiver's did + NSString *receiverDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&receiverDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 3. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 4. add identity + IndyHandle invalidListenerHandle = listenerHandle + 1; + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:invalidListenerHandle + poolHandle:1 + walletHandle:walletHandle + did:receiverDid]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::addIdentityForListenerHandle() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentAddIdentityWorksForTwice +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain did + NSString *did; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. add identity 1 + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for the first attempt"); + + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::addIdentityForListenerHandle() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentAssIdentityWorksForTwoDinOnSameListener +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain did 1 + NSString *did; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. obtain did 2 + NSString *did2; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did2 + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndStoreMyDidWithWalletHandle() failed for did2"); + + // 5. add first identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for did"); + + // 6. add second identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did2]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for did2"); + + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentAddIdentityWorksForInvalidWalletHandle +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain receiver's did + NSString *receiverDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&receiverDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 5. add identity + IndyHandle invalidWalletHandle = walletHandle + 1; + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:1 + walletHandle:invalidWalletHandle + did:receiverDid]; + XCTAssertEqual(ret.code, WalletInvalidHandle, @"AgentUtils::addIdentityForListenerHandle() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentAddIdentityWorksAfterRemove +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain did + NSString *did; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for the first attempt"); + + // 5. remove identity + ret = [[AgentUtils sharedInstance] removeIdentity:did + listenerHandle:listenerHandle + walletHandle:walletHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::removeIdentity() failed"); + + // 6. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for second attempt"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +@end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m index 997c12560a..c3478e99f4 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumListen.m @@ -6,8 +6,6 @@ // Copyright © 2017 Kirill Neznamov. All rights reserved. // -#import - #import #import #import diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m index f356ecf837..fbef994f3a 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumRemoveIdentity.m @@ -7,3 +7,231 @@ // #import +#import +#import +#import "TestUtils.h" + +@interface AgentMediumRemoveIdentity : XCTestCase + +@end + +@implementation AgentMediumRemoveIdentity +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testAgentRemoveIdentityWorksForInvalidListenerHandle +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain did + NSString *did; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for the first attempt"); + + // 5. remove identity + IndyHandle invalidListenerHandle = 0; + ret = [[AgentUtils sharedInstance] removeIdentity:did + listenerHandle:invalidListenerHandle + walletHandle:walletHandle]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::removeIdentity() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentRemoveIdentityWorksForTwice +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain receiver's did + NSString *receiverDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&receiverDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:receiverDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for the first attempt"); + + // 5. remove identity (1) + ret = [[AgentUtils sharedInstance] removeIdentity:receiverDid + listenerHandle:listenerHandle + walletHandle:walletHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::removeIdentity() failed"); + + // 6. remove identity (2) + + ret = [[AgentUtils sharedInstance] removeIdentity:receiverDid + listenerHandle:listenerHandle + walletHandle:walletHandle]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::removeIdentity() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentRemoveIdentityWorksForInvalidWalletHandle +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain did + NSString *did; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:-1 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed for the first attempt"); + + // 5. remove identity + IndyHandle invalidWalletHandle = walletHandle + 1; + ret = [[AgentUtils sharedInstance] removeIdentity:did + listenerHandle:listenerHandle + walletHandle:invalidWalletHandle]; + XCTAssertEqual(ret.code, WalletInvalidHandle, @"AgentUtils::removeIdentity() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentRemoveIdentityWorksForUnknownReceiverDid +{ + [TestUtils cleanupStorage]; + NSError *ret; + NSString *poolName = [TestUtils pool]; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint() failed"); + + // 3. obtain did + NSString *did; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 4. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 5. remove identity + ret = [[AgentUtils sharedInstance] removeIdentity:@"unknownDid" + listenerHandle:listenerHandle + walletHandle:walletHandle]; + XCTAssertEqual(ret.code, WalletNotFoundError, @"AgentUtils::removeIdentity() returned wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + + +@end From 4cf4b72b33a0604a887a5e5b53d2410d190e4b0e Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 16:41:11 +0300 Subject: [PATCH 14/29] iOS: added agent send medium tests --- .../xcschemes/libindy-demo.xcscheme | 3 + .../Case Tests/Agent/AgentMediumCases.m | 128 ------ .../Agent/Medium Cases/AgentMediumSend.m | 382 ++++++++++++++++++ 3 files changed, 385 insertions(+), 128 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/xcshareddata/xcschemes/libindy-demo.xcscheme b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/xcshareddata/xcschemes/libindy-demo.xcscheme index 9b00a536db..48691bc6b8 100644 --- a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/xcshareddata/xcschemes/libindy-demo.xcscheme +++ b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/xcshareddata/xcschemes/libindy-demo.xcscheme @@ -58,6 +58,9 @@ + + diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m index 2b3dd37b9a..7e6089dfad 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m @@ -29,134 +29,6 @@ - (void)tearDown [super tearDown]; } -// MARK: - Add identity -- (void)testAgentAddIdentityWorksForIncomingConnectionRequireLedgerRequestButPoolHandleIsInvalid -{ - [TestUtils cleanupStorage]; - NSError *ret; - NSString *endpoint = @"127.0.0.1:9812"; - NSString *poolName = @"indy_agent_add_identity_works_for_incoming_connection_require_ledger_request_but_pool_handle_is_invalid"; - - // 1. Obtain pool handle - IndyHandle poolHandle = 0; - ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName - poolHandle:&poolHandle]; - XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName() failed"); - - // 2. Obtain listener's wallet - IndyHandle listenerWalletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName - xtype:nil - handle:&listenerWalletHandle]; - XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenWalletWithPoolName() failed"); - - // 3. Obtain trustee's wallet - IndyHandle trusteeWalletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName - xtype:nil - handle:&trusteeWalletHandle]; - XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenWalletWithPoolName() failed"); - - // 4. Create and store listener's did - NSString *listenerDid; - NSString *listenerVerKey; - NSString *listenerPubKey; - ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWalletHandle - seed:nil - outMyDid:&listenerDid - outMyVerkey:&listenerVerKey - outMyPk:&listenerPubKey]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for listener"); - - // 5. create trustee did - - NSString *trusteeDid; - ret =[[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:trusteeWalletHandle - seed:@"000000000000000000000000Trustee1" - outMyDid:&trusteeDid - outMyVerkey:nil - outMyPk:nil]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed for trustee"); - - // 6. Build nym request for listener - NSString *listenerNymRequest; - ret = [[LedgerUtils sharedInstance] buildNymRequestWithSubmitterDid:trusteeDid - targetDid:listenerDid - verkey:listenerVerKey - alias:nil - role:nil - outRequest:&listenerNymRequest]; - XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildNymRequestWithSubmitterDid() failed"); - - // 7. Sign and submit listener's nym request - NSString *listenerNymResponse; - ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle - walletHandle:trusteeWalletHandle - submitterDid:trusteeDid - requestJson:listenerNymRequest - outResponseJson:&listenerNymResponse]; - XCTAssertEqual(ret.code, Success, @"LedgerUtils::signAndSubmitRequestWithPoolHandle() failed for listenerNymRequest"); - - // 8. Build listener attribute request - NSString *rawJson =[NSString stringWithFormat:@"{\"endpoint\":{\"ha\":\"%@\", \"verkey\":\"%@\"}}", endpoint, listenerPubKey]; - NSString *listenerAttributeRequest; - ret = [[LedgerUtils sharedInstance] buildAttribRequestWithSubmitterDid:listenerDid - targetDid:listenerDid - hash:nil - raw:rawJson - enc:nil - resultJson:&listenerAttributeRequest]; - XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildAttribRequestWithSubmitterDid() failed"); - - // 9. Sign and submit listener's attribute request - NSString *listenerAttributeResponse; - ret = [[LedgerUtils sharedInstance] signAndSubmitRequestWithPoolHandle:poolHandle - walletHandle:listenerWalletHandle - submitterDid:listenerDid - requestJson:listenerAttributeRequest - outResponseJson:&listenerAttributeResponse]; - XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildAttribRequestWithSubmitterDid() failed for listenerAttributeResponse"); - - // 10. listen - IndyHandle listenerHandle = 0; - ret = [[AgentUtils sharedInstance] listenForEndpoint:endpoint - connectionCallback:nil - messageCallback:nil - outListenerHandle:&listenerHandle]; - XCTAssertEqual(ret.code, Success, @"LedgerUtils::listenWithEndpoint()"); - - // 11. Add identity - IndyHandle invalidPoolHandle = listenerHandle; - ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle - poolHandle:invalidPoolHandle - walletHandle:listenerWalletHandle - did:listenerDid]; - XCTAssertEqual(ret.code, Success, @"LedgerUtils::addIdentityForListenerHandle() failed for listenerDid"); - - /* TODO - * Currently pool_handle and wallet_handle of add_identity will be checked only at required: - * when listener will check incoming connection and go to ledger for info. - * As result, add_identity will be successful but next connect will fail. - * Possible the test should be split into two: - * - add_identity_works_for_incompatible_pool_and_wallet - * with immediately check in the library - * - connect_works_for_incorrect_connect_request - * actual info in ledger or listener_wallet, wrong public key in sender_wallet - */ - - // 12. Connect - NSString *senderDid = [NSString stringWithString:trusteeDid]; - IndyHandle senderWalletHandle = trusteeWalletHandle; - - ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle - walletHandle:senderWalletHandle - senderDid:senderDid - receiverDid:listenerDid - messageCallback:nil - outConnectionHandle:nil]; - XCTAssertEqual(ret.code, CommonInvalidState, @"AgentUtils::connectWithPoolHandle() returned wrong code"); - [TestUtils cleanupStorage]; -} // MARK: - Close connection diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m index 81bd61470f..045a04b2cf 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumSend.m @@ -7,3 +7,385 @@ // #import +#import +#import +#import "TestUtils.h" + +@interface AgentMediumSend : XCTestCase + +@end + +@implementation AgentMediumSend +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testAgentSendWorksForInvalidConnectionHandle +{ + [TestUtils cleanupStorage]; + NSError *ret; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed"); + + // 2. obtain did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed"); + + // 3. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle failed"); + + // 4. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint failed"); + + // 5. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle failed"); + + // 6. connect + IndyHandle connectionHandle = 0; + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:&connectionHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle failed"); + + // 7. send + IndyHandle invalidConnectionHandle = connectionHandle + 100; + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:invalidConnectionHandle + message:[TestUtils clientMessage]]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::sendWithConnectionHandler returned wrong code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentSendWorksForClosedConnection +{ + [TestUtils cleanupStorage]; + NSError *ret; + + // 1. wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed"); + + // 2. obtain did + + NSString *did; + NSString *verkey; + NSString *pubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verkey + outMyPk:&pubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed"); + + // 3. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubkey + theirVerkey:verkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle failed"); + + // 4. listen + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenForEndpoint failed"); + + // 5. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle failed"); + + // 6. connect + IndyHandle connectionHandle = 0; + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:&connectionHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle failed"); + + // 7. close connection + ret = [[AgentUtils sharedInstance] closeConnection:connectionHandle]; + + // 7. send + IndyHandle invalidConnectionHandle = connectionHandle + 100; + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:invalidConnectionHandle + message:[TestUtils clientMessage]]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::sendWithConnectionHandler returned wrong code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentSendWorksForClosedListenerIncomingConenction +{ + [TestUtils cleanupStorage]; + NSString *poolName = [TestUtils pool]; + NSError *ret; + + // 1. pool ledger + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName failed"); + + // 2. listener wallet + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for listenerWallet"); + + // 3. sender wallet + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for senderWallet"); + + // 4. obtain listener's did + NSString *listenerDid; + NSString *listenerVerkey; + NSString *listenerPubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerkey + outMyPk:&listenerPubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for listenerDid"); + + // 5. obtain sender did + NSString *senderDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:[TestUtils trusteeSeed] + outMyDid:&senderDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for senderDid"); + + // 6. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:senderWallet + theirDid:listenerDid + theirPk:listenerPubkey + theirVerkey:listenerVerkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle failed"); + + // 7. listen + + // connection callback + XCTestExpectation* listenerConnectionCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; + __block IndyHandle connectionHandleFromCallback; + void (^connectionCallback)(IndyHandle, IndyHandle) = ^(IndyHandle xListenerHandle, IndyHandle xConnectionHandle) { + NSLog(@"AgentHighCases::testAgentListenWorksForPassedOnConnectCallback:: listener's connectionCallback triggered."); + connectionHandleFromCallback = xConnectionHandle; + [listenerConnectionCompletionExpectation fulfill]; + + }; + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:connectionCallback + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::listenForEndpoint failed"); + + // 8. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle failed"); + + // 9. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle failed"); + + [self waitForExpectations:@[listenerConnectionCompletionExpectation] timeout:[TestUtils shortTimeout]]; + + // 10. close listener + ret = [[AgentUtils sharedInstance] closeListener:listenerHandle]; + + // 11. send + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandleFromCallback + message:[TestUtils serverMessage]]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::sendWithConnectionHandler return wrong error code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [TestUtils cleanupStorage]; +} + +// TODO: This test is disabled in Rust +- (void)testAgentSendWorksForRemovedIdentity +{ + [TestUtils cleanupStorage]; + NSString *poolName = [TestUtils pool]; + NSError *ret; + + // 1. pool ledger + IndyHandle poolHandle = 0; + ret = [[PoolUtils sharedInstance] createAndOpenPoolLedgerConfigWithName:poolName + poolHandle:&poolHandle]; + XCTAssertEqual(ret.code, Success, @"PoolUtils::createAndOpenPoolLedgerConfigWithName failed"); + + // 2. listener wallet + IndyHandle listenerWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&listenerWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for listenerWallet"); + + // 3. sender wallet + IndyHandle senderWallet = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + xtype:nil + handle:&senderWallet]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed for senderWallet"); + + // 4. obtain listener's did + NSString *listenerDid; + NSString *listenerVerkey; + NSString *listenerPubkey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:listenerWallet + seed:nil + outMyDid:&listenerDid + outMyVerkey:&listenerVerkey + outMyPk:&listenerPubkey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for listenerDid"); + + // 5. obtain sender did + NSString *senderDid; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:senderWallet + seed:[TestUtils trusteeSeed] + outMyDid:&senderDid + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle failed for senderDid"); + + // 6. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:senderWallet + theirDid:listenerDid + theirPk:listenerPubkey + theirVerkey:listenerVerkey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle failed"); + + // 7. listen + + // connection callback + XCTestExpectation* listenerConnectionCompletionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"listener completion finished"]; + __block IndyHandle connectionHandleFromCallback; + void (^connectionCallback)(IndyHandle, IndyHandle) = ^(IndyHandle xListenerHandle, IndyHandle xConnectionHandle) { + NSLog(@"AgentHighCases::testAgentListenWorksForPassedOnConnectCallback:: listener's connectionCallback triggered."); + connectionHandleFromCallback = xConnectionHandle; + [listenerConnectionCompletionExpectation fulfill]; + + }; + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:connectionCallback + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::listenForEndpoint failed"); + + // 8. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:poolHandle + walletHandle:listenerWallet + did:listenerDid]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle failed"); + + // 9. connect + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:poolHandle + walletHandle:senderWallet + senderDid:senderDid + receiverDid:listenerDid + messageCallback:nil + outConnectionHandle:nil]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle failed"); + + [self waitForExpectations:@[listenerConnectionCompletionExpectation] timeout:[TestUtils shortTimeout]]; + + + + // 10. remove identity + ret = [[AgentUtils sharedInstance] removeIdentity:listenerDid + listenerHandle:listenerHandle + walletHandle:listenerWallet]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::removeIdentity failed"); + + // 11. send + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandleFromCallback + message:[TestUtils serverMessage]]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::sendWithConnectionHandler return wrong error code"); + + [[AgentUtils sharedInstance] closeListener:listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle:listenerWallet]; + [[WalletUtils sharedInstance] closeWalletWithHandle:senderWallet]; + [[PoolUtils sharedInstance] closeHandle:poolHandle]; + [TestUtils cleanupStorage]; +} + + + +@end From 975abf01c5464978b666fbe41d88da7f38a27ca5 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 16:53:36 +0300 Subject: [PATCH 15/29] iOS: added agent close connection medium tests --- .../Case Tests/Agent/AgentMediumCases.m | 86 -------- .../Medium Cases/AgentMediumCloseConnection.m | 183 ++++++++++++++++++ 2 files changed, 183 insertions(+), 86 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m index 7e6089dfad..6e0561f57a 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m @@ -29,92 +29,6 @@ - (void)tearDown [super tearDown]; } - -// MARK: - Close connection - -- (void)testAgentCloseConnectionWorksForIncorrectConnectionHandle -{ - [TestUtils cleanupStorage]; - NSError *ret; - - // 1. create and open wallet handle - IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool6" - xtype:nil - handle:&walletHandle]; - XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); - - // 2. obtain did - NSString *did; - NSString *verKey; - NSString *pubKey; - ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:nil - outMyDid:&did - outMyVerkey:&verKey - outMyPk:&pubKey]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); - - // 3. listen - NSString *endpoint = @"127.0.0.1:9807"; - - XCTestExpectation* messageExpectation = [[ XCTestExpectation alloc] initWithDescription: @"message completion finished"]; - - IndyHandle listenerHandler = 0; - __block NSString* messageFromClient; - ret = [[AgentUtils sharedInstance] listenForEndpoint:endpoint - connectionCallback:nil - messageCallback:^(IndyHandle connectionHandle, NSString *message) - { - messageFromClient = message; - [messageExpectation fulfill]; - } - outListenerHandle:&listenerHandler]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::listenWithEndpoint() failed"); - - // 4. add identity - ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandler - poolHandle:-1 - walletHandle:walletHandle - did:did]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); - - // 5. store their did from parts - ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle - theirDid:did - theirPk:pubKey - theirVerkey:verKey - endpoint:endpoint]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::storeTheirDidFromPartsWithWalletHandle() failed"); - - // 6. Connect - IndyHandle connectionHandle = 0; - ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 - walletHandle:walletHandle - senderDid:did - receiverDid:did - messageCallback:nil - outConnectionHandle:&connectionHandle]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); - - // 7. Close connection - ret = [[AgentUtils sharedInstance] closeConnection:connectionHandle + 100]; - XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::closeConnection() returned wrong code"); - - // 8. send - NSString *clientMessage = @"msg_from_cli_to_srv"; - ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandle - message:clientMessage]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::sendWithConnectionHandler() failed"); - - // 9. wait for message callback - [self waitForExpectations: @[messageExpectation] timeout:[TestUtils defaultTimeout]]; - - XCTAssertTrue([messageFromClient isEqualToString:clientMessage], @"wrong message from client!"); - - [TestUtils cleanupStorage]; -} - // MARK: - Close listener - (void)testAgentCloseListenerWorksForIncorrectHandle diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m index be73e3532b..1f7585e272 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseConnection.m @@ -7,3 +7,186 @@ // #import +#import +#import +#import "TestUtils.h" + +@interface AgentMediumCloseConnection : XCTestCase + +@end + +@implementation AgentMediumCloseConnection +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +// MARK: - Close connection + +- (void)testAgentCloseConnectionWorksForIncorrectConnectionHandle +{ + [TestUtils cleanupStorage]; + NSError *ret; + + // 1. create and open wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain did + NSString *did; + NSString *verKey; + NSString *pubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verKey + outMyPk:&pubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + + // 3. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubKey + theirVerkey:verKey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 4. listen + + XCTestExpectation* messageExpectation = [[ XCTestExpectation alloc] initWithDescription: @"message completion finished"]; + + IndyHandle listenerHandler = 0; + __block NSString* messageFromClient; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:^(IndyHandle connectionHandle, NSString *message) + { + messageFromClient = message; + [messageExpectation fulfill]; + } + outListenerHandle:&listenerHandler]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenWithEndpoint() failed"); + + // 5. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandler + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 6. Connect + IndyHandle connectionHandle = 0; + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:&connectionHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); + + // 7. Close connection + ret = [[AgentUtils sharedInstance] closeConnection:connectionHandle + 100]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::closeConnection() returned wrong code"); + + // 8. send + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandle + message:[TestUtils clientMessage]]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::sendWithConnectionHandler() failed"); + + // 9. wait for message callback + [self waitForExpectations: @[messageExpectation] timeout:[TestUtils defaultTimeout]]; + + XCTAssertTrue([messageFromClient isEqualToString:[TestUtils clientMessage]], @"wrong message from client!"); + + [[AgentUtils sharedInstance] closeListener: listenerHandler]; + [[WalletUtils sharedInstance] closeWalletWithHandle: walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentCloseConnectionWorksForTwice +{ + [TestUtils cleanupStorage]; + NSError *ret; + + // 1. create and open wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain did + NSString *did; + NSString *verKey; + NSString *pubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verKey + outMyPk:&pubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + + // 3. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubKey + theirVerkey:verKey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 4. listen + + IndyHandle listenerHandle = 0; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenWithEndpoint() failed"); + + // 5. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandle + poolHandle:0 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 6. Connect + IndyHandle connectionHandle = 0; + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:&connectionHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); + + // 7. Close connection (1) + ret = [[AgentUtils sharedInstance] closeConnection:connectionHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::closeConnection() failed for the first attempt"); + + // 8. Close connection (2) + ret = [[AgentUtils sharedInstance] closeConnection:connectionHandle]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::closeConnection() returned wrong error code"); + + + [[AgentUtils sharedInstance] closeListener: listenerHandle]; + [[WalletUtils sharedInstance] closeWalletWithHandle: walletHandle]; + + [TestUtils cleanupStorage]; +} + + +@end From 64a83f602b24fd570c752b3c131494d8226923f7 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 17:22:42 +0300 Subject: [PATCH 16/29] iOS: added agent close listener medium tests --- .../Medium Cases/AgentMediumCloseListener.m | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m index d44e04f6fc..06aecb4f2b 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/Medium Cases/AgentMediumCloseListener.m @@ -7,3 +7,177 @@ // #import + + +#import +#import +#import +#import "TestUtils.h" + +@interface AgentMediumCloseListener : XCTestCase + +@end + +@implementation AgentMediumCloseListener +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testAgentCloseListenerWorksForIncorrectHandle +{ + [TestUtils cleanupStorage]; + NSError *ret; + + // 1. create and open wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain did + NSString *did; + NSString *verKey; + NSString *pubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verKey + outMyPk:&pubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 3. listen + + XCTestExpectation* messageExpectation = [[ XCTestExpectation alloc] initWithDescription: @"message completion finished"]; + + IndyHandle listenerHandler = 0; + __block NSString* messageFromClient; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:^(IndyHandle connectionHandle, NSString *message) + { + messageFromClient = message; + [messageExpectation fulfill]; + } + outListenerHandle:&listenerHandler]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenWithEndpoint() failed"); + + // 4. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandler + poolHandle:-1 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 5. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubKey + theirVerkey:verKey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 6. Connect + IndyHandle connectionHandle = 0; + ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 + walletHandle:walletHandle + senderDid:did + receiverDid:did + messageCallback:nil + outConnectionHandle:&connectionHandle]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); + + // 7. Close listener + IndyHandle incorrectListenerHandle = connectionHandle; + ret = [[AgentUtils sharedInstance] closeListener:incorrectListenerHandle]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::closeListener() returned wrong code"); + + // 8. send + ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandle + message:[TestUtils clientMessage]]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::sendWithConnectionHandler() failed"); + + // 9. wait for message callback + [self waitForExpectations: @[messageExpectation] timeout:[TestUtils defaultTimeout]]; + + XCTAssertTrue([messageFromClient isEqualToString:[TestUtils clientMessage]], @"wrong message from client!"); + + [[AgentUtils sharedInstance] closeListener: listenerHandler]; + [[WalletUtils sharedInstance] closeWalletWithHandle: walletHandle]; + + [TestUtils cleanupStorage]; +} + +- (void)testAgentCloseListenerWorksForTwice +{ + [TestUtils cleanupStorage]; + NSError *ret; + + // 1. create and open wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); + + // 2. obtain did + NSString *did; + NSString *verKey; + NSString *pubKey; + ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle + seed:nil + outMyDid:&did + outMyVerkey:&verKey + outMyPk:&pubKey]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); + + // 3. store their did from parts + ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle + theirDid:did + theirPk:pubKey + theirVerkey:verKey + endpoint:[TestUtils endpoint]]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::storeTheirDidFromPartsWithWalletHandle() failed"); + + // 4. listen + + IndyHandle listenerHandler = 0; + __block NSString* messageFromClient; + ret = [[AgentUtils sharedInstance] listenForEndpoint:[TestUtils endpoint] + connectionCallback:nil + messageCallback:nil + outListenerHandle:&listenerHandler]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::listenWithEndpoint() failed"); + + // 5. add identity + ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandler + poolHandle:-1 + walletHandle:walletHandle + did:did]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); + + // 6. Close listener (1) + + IndyHandle connectionHandle = 0; + ret = [[AgentUtils sharedInstance] closeListener:listenerHandler]; + XCTAssertEqual(ret.code, Success, @"AgentUtils::closeListener() failed"); + + // 7. Close listener (2) + + ret = [[AgentUtils sharedInstance] closeListener:listenerHandler]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::closeListener() returned wrong code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle: walletHandle]; + + [TestUtils cleanupStorage]; +} + +@end From eaf7a887152c2e8e773d13bbebe478b2251fce93 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 17:50:02 +0300 Subject: [PATCH 17/29] iOS: Updated signus tests --- .../libindy-demo.xcodeproj/project.pbxproj | 4 - .../Case Tests/Agent/AgentHighCases.m | 2 +- .../Case Tests/Agent/AgentMediumCases.m | 119 ------------- .../Anoncreds/AnoncredsMediumCases.m | 4 +- .../Anoncreds/AnoncredsMediumCasesDemos.m | 8 +- .../Case Tests/Ledger/LedgerHignCases.mm | 2 +- .../Case Tests/Signus/SignusHighCases.m | 166 +++++++++++++++--- .../Case Tests/Signus/SignusMediumCases.m | 14 +- .../Demo Tests/AnoncredsDemo.mm | 2 +- .../Demo Tests/SignusDemo.mm | 2 +- .../Test Utils/AnoncredsUtils.m | 2 +- 11 files changed, 163 insertions(+), 162 deletions(-) delete mode 100644 wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m diff --git a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj index 22485def96..8dfda9f97f 100644 --- a/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj +++ b/wrappers/ios/libindy-pod/libindy-demo.xcodeproj/project.pbxproj @@ -25,7 +25,6 @@ 5DF013E21F1604C200076592 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF013DB1F1604C200076592 /* ViewController.m */; }; 5DF0149D1F1605EB00076592 /* Base58Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF014661F1605EB00076592 /* Base58Test.m */; }; 5DF0149E1F1605EB00076592 /* AgentHighCases.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF014691F1605EB00076592 /* AgentHighCases.m */; }; - 5DF0149F1F1605EB00076592 /* AgentMediumCases.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF0146A1F1605EB00076592 /* AgentMediumCases.m */; }; 5DF014A01F1605EB00076592 /* AnoncredsHighCases.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF0146C1F1605EB00076592 /* AnoncredsHighCases.m */; }; 5DF014A11F1605EB00076592 /* AnoncredsMediumCases.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF0146D1F1605EB00076592 /* AnoncredsMediumCases.m */; }; 5DF014A21F1605EB00076592 /* AnoncredsMediumCasesDemos.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DF0146E1F1605EB00076592 /* AnoncredsMediumCasesDemos.m */; }; @@ -118,7 +117,6 @@ 5DF013DB1F1604C200076592 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 5DF014661F1605EB00076592 /* Base58Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Base58Test.m; sourceTree = ""; }; 5DF014691F1605EB00076592 /* AgentHighCases.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentHighCases.m; sourceTree = ""; }; - 5DF0146A1F1605EB00076592 /* AgentMediumCases.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AgentMediumCases.m; sourceTree = ""; }; 5DF0146C1F1605EB00076592 /* AnoncredsHighCases.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnoncredsHighCases.m; sourceTree = ""; }; 5DF0146D1F1605EB00076592 /* AnoncredsMediumCases.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnoncredsMediumCases.m; sourceTree = ""; }; 5DF0146E1F1605EB00076592 /* AnoncredsMediumCasesDemos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnoncredsMediumCasesDemos.m; sourceTree = ""; }; @@ -271,7 +269,6 @@ children = ( 5D0481B41F46E16B00ED79A2 /* Medium Cases */, 5DF014691F1605EB00076592 /* AgentHighCases.m */, - 5DF0146A1F1605EB00076592 /* AgentMediumCases.m */, ); path = Agent; sourceTree = ""; @@ -618,7 +615,6 @@ 5DF014A41F1605EB00076592 /* LedgerHignCases.mm in Sources */, 5DF014AC1F1605EB00076592 /* WalletHighCases.m in Sources */, 5DF014B41F1605EB00076592 /* ClosureUtils.m in Sources */, - 5DF0149F1F1605EB00076592 /* AgentMediumCases.m in Sources */, 5DF014B91F1605EB00076592 /* TestUtils.m in Sources */, 5D0481C31F46FF4000ED79A2 /* AgentMediumCloseListener.m in Sources */, 5DF014A31F1605EB00076592 /* LedgerAttribRequest.mm in Sources */, diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m index 28d6c3d35c..43f1370f25 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentHighCases.m @@ -222,7 +222,7 @@ - (void)testAgentConnectWorksForAllDataInWalletPresent // 1. obtain wallet handle IndyHandle walletHandle; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m deleted file mode 100644 index 6e0561f57a..0000000000 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Agent/AgentMediumCases.m +++ /dev/null @@ -1,119 +0,0 @@ -// -// AgentMediumCases.m -// libindy-demo -// -// Created by Anastasia Tarasova on 22.06.17. -// Copyright © 2017 Kirill Neznamov. All rights reserved. -// - -#import -#import -#import -#import "TestUtils.h" - -@interface AgentMediumCases : XCTestCase - -@end - -@implementation AgentMediumCases - -- (void)setUp -{ - [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. -} - -- (void)tearDown -{ - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; -} - -// MARK: - Close listener - -- (void)testAgentCloseListenerWorksForIncorrectHandle -{ - [TestUtils cleanupStorage]; - NSError *ret; - - // 1.Create and open wallet - IndyHandle walletHandle; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool9" - xtype:nil - handle:&walletHandle]; - XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName() failed"); - - // 2. obtain did - NSString *did; - NSString *verKey; - NSString *pubKey; - ret = [[SignusUtils sharedInstance] createAndStoreMyDidWithWalletHandle:walletHandle - seed:nil - outMyDid:&did - outMyVerkey:&verKey - outMyPk:&pubKey]; - XCTAssertEqual(ret.code, Success, @"SignusUtils::createAndStoreMyDidWithWalletHandle() failed"); - - // 3. listen - NSString *endpoint = @"127.0.0.1:9809"; - - XCTestExpectation* messageExpectation = [[ XCTestExpectation alloc] initWithDescription: @"message completion finished"]; - - IndyHandle listenerHandler = 0; - __block NSString* messageFromClient; - ret = [[AgentUtils sharedInstance] listenForEndpoint:endpoint - connectionCallback:nil - messageCallback:^(IndyHandle connectionHandle, NSString *message) - { - messageFromClient = message; - [messageExpectation fulfill]; - } - outListenerHandle:&listenerHandler]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::listenWithEndpoint() failed"); - - // 4. add identity - ret = [[AgentUtils sharedInstance] addIdentityForListenerHandle:listenerHandler - poolHandle:-1 - walletHandle:walletHandle - did:did]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::addIdentityForListenerHandle() failed"); - - // 5. store their did from parts - ret = [[SignusUtils sharedInstance] storeTheirDidFromPartsWithWalletHandle:walletHandle - theirDid:did - theirPk:pubKey - theirVerkey:verKey - endpoint:endpoint]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::storeTheirDidFromPartsWithWalletHandle() failed"); - - // 6. Connect - IndyHandle connectionHandle = 0; - ret = [[AgentUtils sharedInstance] connectWithPoolHandle:0 - walletHandle:walletHandle - senderDid:did - receiverDid:did - messageCallback:nil - outConnectionHandle:&connectionHandle]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::connectWithPoolHandle() failed"); - - // 7. close listener - IndyHandle incorrectListenerHandle = connectionHandle; // + 1; - ret = [[AgentUtils sharedInstance] closeListener:incorrectListenerHandle]; - XCTAssertEqual(ret.code, CommonInvalidStructure, @"AgentUtils::closeListener() returned wrong code"); - - // 8. send - NSString *clientMessage = @"msg_from_cli_to_srv"; - ret = [[AgentUtils sharedInstance] sendWithConnectionHandler:connectionHandle - message:clientMessage]; - XCTAssertEqual(ret.code, Success, @"AgentUtils::sendWithConnectionHandler() failed"); - - // 9. wait for message callback - [self waitForExpectations: @[messageExpectation] timeout:[TestUtils defaultTimeout]]; - - XCTAssertTrue([messageFromClient isEqualToString:clientMessage], @"wrong message from client!"); - - [TestUtils cleanupStorage]; -} - - -@end diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCases.m index 80d65b1229..520f07783b 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCases.m @@ -162,13 +162,13 @@ - (void)testProverGetClaimOffersWorksForDifferentWallets // 2. obtain wallet handles IndyHandle walletHandle1 = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle1]; XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed"); IndyHandle walletHandle2 = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle2]; XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed"); diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCasesDemos.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCasesDemos.m index 976df0272e..3d2e9f8dfd 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCasesDemos.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsMediumCasesDemos.m @@ -42,7 +42,7 @@ - (void)testVerifierVerifyProofWorksForProofDoesNotCorrespondProofRequest //1. Create wallet, get wallet handle NSError *ret; IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed"); @@ -173,7 +173,7 @@ - (void)testAnoncredsWorksForSingleIssuerSingleProver { [TestUtils cleanupStorage]; - NSString* poolName = @"pool1"; + NSString* poolName = [TestUtils pool]; IndyHandle issuerWalletHandle = 0; IndyHandle proverWalletHandle = 0; NSError *ret = nil; @@ -356,7 +356,7 @@ - (void)testAnoncredsWorksForMultiplyIssuerSingleProver NSString *issuer2Did = @"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; NSString *proverDid = @"BzfFCYk"; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; NSError *ret; //1. Issuer1 create wallet, get wallet handles @@ -703,7 +703,7 @@ - (void)testAnoncredsWorksForSingleIssuerMultiplyClaimsSingleProver NSString* issuerDid = @"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; NSString* proverDid = @"BzfFCYk"; - NSString* poolName = @"pool1"; + NSString* poolName = [TestUtils pool]; NSError* ret = nil; //1. Issuer create wallet, get wallet handles diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Ledger/LedgerHignCases.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Ledger/LedgerHignCases.mm index c0e1a4bfec..9eb68d5aee 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Ledger/LedgerHignCases.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Ledger/LedgerHignCases.mm @@ -307,7 +307,7 @@ -(void) testSignAndSubmitRequestWorksForInvalidWalletHandle - (void) testSignAndSubmitRequestWorksForIncompatibleWalletAndPool { [TestUtils cleanupStorage]; - NSString *poolName1 = @"pool1"; + NSString *poolName1 = [TestUtils pool]; NSString *poolName2 = @"pool2"; NSError *ret; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m index 1b079bf020..89a9f1e2ae 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusHighCases.m @@ -40,12 +40,11 @@ - (void)tearDown - (void)testCreateMyDidWorksForEmptyJson { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -62,19 +61,18 @@ - (void)testCreateMyDidWorksForEmptyJson XCTAssertEqual([[myDid dataFromBase58] length] , 16, @"length of myDid != 16"); XCTAssertEqual([[myVerKey dataFromBase58] length], 32, @"length of myVerKey != 32"); - + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } - (void)testCreateMyDidWorksWithSeed { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -92,18 +90,18 @@ - (void)testCreateMyDidWorksWithSeed XCTAssertTrue([myDid isEqualToString:@"NcYxiDXkpYi6ov5FcYDi1e"], @"wrong myDid!"); XCTAssertTrue([myVerKey isEqualToString:@"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"], @"wrong myVerKey!"); + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } - (void)testCreateMyDidWorksAsCid { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -122,18 +120,19 @@ - (void)testCreateMyDidWorksAsCid XCTAssertTrue([myDid isEqualToString:@"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"], @"wrong myDid!"); XCTAssertTrue([myVerKey isEqualToString:@"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"], @"wrong myVerKey!"); + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } - (void)testCreateMyDidWorksWithPassedDid { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -154,18 +153,44 @@ - (void)testCreateMyDidWorksWithPassedDid XCTAssertTrue([myDid isEqualToString:did], @"wrong myDid!"); XCTAssertTrue([myVerKey isEqualToString:@"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"], @"wrong myVerKey!"); + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; +} + +- (void)testCreateMyDidWorkForExistsCryptoType +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. create my did + ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle + myDidJson:@"{\"crypto_type\":\"ed25519\"}" + outMyDid:nil + outMyVerkey:nil + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() returned wrong error code"); + + // 3. close wallet + [[WalletUtils sharedInstance] closeWalletWithHandle: walletHandle]; + [TestUtils cleanupStorage]; } - (void)testCreateMyDidWorksForinvalidWalletHandle { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -178,6 +203,8 @@ - (void)testCreateMyDidWorksForinvalidWalletHandle outMyVerkey:nil outMyPk:nil]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils::createMyDidWithWalletHandle() returned wrong error code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -186,12 +213,11 @@ - (void)testCreateMyDidWorksForinvalidWalletHandle - (void)testReplaceKeysWorks { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -211,18 +237,19 @@ - (void)testReplaceKeysWorks identityJson:@"{}" outMyVerKey:nil outMyPk:nil]; + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } - (void)testReplaceKeysWorksForInvalidDid { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -234,18 +261,19 @@ - (void)testReplaceKeysWorksForInvalidDid outMyVerKey:nil outMyPk:nil]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils:replaceKeysWithWalletHandle failed"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } - (void)testReplaceKeysWorksForInvalidHandle { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; NSError *ret = nil; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:poolName + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -267,6 +295,47 @@ - (void)testReplaceKeysWorksForInvalidHandle outMyVerKey:nil outMyPk:nil]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils:replaceKeysWithWalletHandle failed"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; +} + +- (void)testReplaceKeysWorksForSeed +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. create my did + NSString *myDid; + NSString *myVerkey; + ret = [[SignusUtils sharedInstance] createMyDidWithWalletHandle:walletHandle + myDidJson:@"{}" + outMyDid:&myDid + outMyVerkey:&myVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDidWithWalletHandle() returned wrong error code"); + + // 3. replace keys + + NSString *newVerkey; + ret = [[SignusUtils sharedInstance] replaceKeysWithWalletHandle:walletHandle + did:myDid + identityJson:@"{\"seed\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}" + outMyVerKey:&newVerkey + outMyPk:nil]; + XCTAssertEqual(ret.code, Success, @"SignusUtils:replaceKeysWithWalletHandle failed"); + XCTAssertTrue([newVerkey isEqualToString:@"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"], @"wrong newVerkey"); + XCTAssertFalse([myVerkey isEqualToString:newVerkey], @"verkey is the same!"); + + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -278,7 +347,7 @@ - (void)testStoreTheidDidWorks // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -288,6 +357,8 @@ - (void)testStoreTheidDidWorks ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, Success, @"SignusUtils:storeTheirDid failed"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -298,7 +369,7 @@ - (void)testStoreTheirDidWorksForInvalidJson // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -308,6 +379,8 @@ - (void)testStoreTheirDidWorksForInvalidJson ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils:storeTheirDid returned wrong error"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -318,7 +391,7 @@ - (void)testStoreTheirDidWorksForInvalidHandle // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -329,6 +402,8 @@ - (void)testStoreTheirDidWorksForInvalidHandle ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:invalidWalletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"SignusUtils:storeTheirDid returned wrong error"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -339,7 +414,7 @@ - (void)testStoreTheirDidWorksWithVerkey // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&walletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); @@ -350,6 +425,53 @@ - (void)testStoreTheirDidWorksWithVerkey ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle identityJson:identityJson]; XCTAssertEqual(ret.code, Success, @"SignusUtils:storeTheirDid() failed"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; +} + +- (void)testStoretheirDidWorksWithoutDid +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. Store their did + NSString *identityJson = @"{\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"}"; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, CommonInvalidStructure, @"SignusUtils:storeTheirDidWithWalletHandle() returned wrong code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; + [TestUtils cleanupStorage]; + +} + +- (void)testStoreTheirDidWorksForCorrectCryptoType +{ + [TestUtils cleanupStorage]; + NSError *ret = nil; + + // 1. Create and open wallet, get wallet handle + IndyHandle walletHandle = 0; + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + xtype:nil + handle:&walletHandle]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:createAndOpenWalletWithPoolName failed"); + + // 2. Store their did + NSString *identityJson = @"{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\", \"crypto_type\": \"ed25519\"}"; + ret = [[SignusUtils sharedInstance] storeTheirDidWithWalletHandle:walletHandle + identityJson:identityJson]; + XCTAssertEqual(ret.code, Success, @"SignusUtils:storeTheirDidWithWalletHandle() failed"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -386,6 +508,7 @@ - (void)testSignWorks outSignature:&signature]; XCTAssertTrue([signature isEqualToData:[TestUtils signature]], @"SignusUtils::signWithWalletHandle() failed. Signature is not verified"); + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } @@ -408,6 +531,7 @@ - (void)testSignWorksForUnknownSigner outSignature:&signature]; XCTAssertEqual(ret.code, WalletNotFoundError, @"SignusUtils::signWithWalletHandle() returned wrong error"); + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; [TestUtils cleanupStorage]; } diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m index fffb977c18..112795c6a3 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Signus/SignusMediumCases.m @@ -40,7 +40,7 @@ - (void)testCreateMyDidWorksForInvalidCryptoType { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -65,7 +65,7 @@ - (void)testCreateMyDidWorksForInvalidSeed { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -90,7 +90,7 @@ - (void)testCreateMyDidWorksForInvalidDid { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -115,7 +115,7 @@ - (void)testCreateMyDidWorksForInvalidJson { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -249,7 +249,7 @@ - (void)testStoreTheirDidWorksForInvalidCryptoType { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -271,7 +271,7 @@ - (void)testStoreTheirDidWorksForInvalidDid { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; @@ -293,7 +293,7 @@ - (void)testStoreTheirDidWorksForInvalidVerkey { [TestUtils cleanupStorage]; NSError *ret = nil; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; // 1. Create and open wallet, get wallet handle IndyHandle walletHandle = 0; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/AnoncredsDemo.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/AnoncredsDemo.mm index e538415e71..e17057e674 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/AnoncredsDemo.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/AnoncredsDemo.mm @@ -32,7 +32,7 @@ - (void)tearDown - (void)testAnoncredsDemo { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; NSString *walletName = @"issuer_wallet"; NSString *xType = @"default"; XCTestExpectation *completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm b/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm index 32eaf9c036..cd03ea0647 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Demo Tests/SignusDemo.mm @@ -32,7 +32,7 @@ - (void)testSignusDemo { [TestUtils cleanupStorage]; - NSString *poolName = @"pool1"; + NSString *poolName = [TestUtils pool]; NSString *myWalletName = @"my_wallet4"; NSString *theirWalletName = @"their_wallet5"; NSString *xtype = @"default"; diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m index 1053ac8ecd..d7ba5d5f5c 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m @@ -562,7 +562,7 @@ - (NSError *)initializeCommonWalletAndReturnHandle:(IndyHandle *)walletHandle // 1. Create and open wallet self.walletHandle = 0; IndyHandle tempWalletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] xtype:nil handle:&tempWalletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed"); From e227e89c26e61fd0439fd2206fb7203481e58212 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Fri, 18 Aug 2017 18:14:46 +0300 Subject: [PATCH 18/29] fixing anoncreds tests --- .../Case Tests/Anoncreds/AnoncredsHighCases.m | 24 ++++++++++++++++--- .../Test Utils/AnoncredsUtils.m | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m index 5bd4e9fa4b..aaf22ab3fd 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m @@ -512,9 +512,9 @@ - (void)testIssuerCreateClaimWorks // 2. create claim NSString *claimRequest = [NSString stringWithFormat: @"{"\ "\"blinded_ms\":{"\ - "\"prover_did\":\"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW\","\ - "\"u\":\"54172737564529332710724213139048941083013176891644677117322321823630308734620627329227591845094100636256829761959157314784293939045176621327154990908459072821826818718739696323299787928173535529024556540323709578850706993294234966440826690899266872682790228513973999212370574548239877108511283629423807338632435431097339875665075453785141722989098387895970395982432709011505864533727415552566715069675346220752584449560407261446567731711814188836703337365986725429656195275616846543535707364215498980750860746440672050640048215761507774996460985293327604627646056062013419674090094698841792968543317468164175921100038\","\ - "\"ur\":null},"\ + "\"prover_did\":\"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW\","\ + "\"u\":\"54172737564529332710724213139048941083013176891644677117322321823630308734620627329227591845094100636256829761959157314784293939045176621327154990908459072821826818718739696323299787928173535529024556540323709578850706993294234966440826690899266872682790228513973999212370574548239877108511283629423807338632435431097339875665075453785141722989098387895970395982432709011505864533727415552566715069675346220752584449560407261446567731711814188836703337365986725429656195275616846543535707364215498980750860746440672050640048215761507774996460985293327604627646056062013419674090094698841792968543317468164175921100038\","\ + "\"ur\":null},"\ "\"issuer_did\":\"%@\","\ "\"schema_seq_no\":1}", [AnoncredsUtils issuerDid]]; @@ -533,6 +533,8 @@ - (void)testIssuerCreateClaimWorks XCTAssertTrue([claim[@"signature"][@"primary_claim"][@"m2"] length] > 0, @"wrong \"m2\" length"); XCTAssertTrue([claim[@"signature"][@"primary_claim"][@"e"] length] > 0, @"wrong \"e\" length"); XCTAssertTrue([claim[@"signature"][@"primary_claim"][@"v"] length] > 0, @"wrong \"v\" length"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } - (void)testIssuerCreateClaimWorksForClaimDoesNotCorrespondToClaimReq @@ -593,6 +595,8 @@ - (void)testIssuerCreateClaimWorksForInvalidWalletHandle outRevocRegUpdateJSON:nil]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"AnoncredsUtils::issuerCreateClaimWithWalletHandle returned wrong error code."); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } // MARK: - Prover store claim @@ -641,6 +645,8 @@ - (void)testProverStoreClaimWorks ret = [[AnoncredsUtils sharedInstance] proverStoreClaimWithWalletHandle:walletHandle claimsJson:xClaimJson]; XCTAssertEqual(ret.code, Success, @"AnoncredsUtils::proverStoreClaimWithWalletHandle failed"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } - (void)testProverStoreClaimWorksForInvalidWalletHandle @@ -689,6 +695,8 @@ - (void)testProverStoreClaimWorksForInvalidWalletHandle ret = [[AnoncredsUtils sharedInstance] proverStoreClaimWithWalletHandle:invalidWalletHandle claimsJson:xClaimJson]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"AnoncredsUtils::proverStoreClaimWithWalletHandle failed"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } // MARK: - Prover get claims @@ -715,6 +723,8 @@ - (void)testProverGetClaimsWorksForEmptyFilter NSArray *claims = (NSArray *)claimsDict; XCTAssertEqual([claims count], 1, @"claims count != 1"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } - (void)testProverGetClaimsWorksForFilterByIssuerDid @@ -740,6 +750,8 @@ - (void)testProverGetClaimsWorksForFilterByIssuerDid NSArray *claims = (NSArray *)claimsDict; XCTAssertEqual([claims count], 1, @"claims count != 1"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } - (void)testProverGetClaimsWorksForFilterByClaimDefSeqNoAndSchemaSeqNo @@ -765,6 +777,8 @@ - (void)testProverGetClaimsWorksForFilterByClaimDefSeqNoAndSchemaSeqNo NSArray *claims = (NSArray *)claimsDict; XCTAssertEqual([claims count], 1, @"claims count != 1"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } - (void)testProverGetClaimsWorksForEmptyResult @@ -789,6 +803,8 @@ - (void)testProverGetClaimsWorksForEmptyResult NSArray *claims = (NSArray *)claimsDict; XCTAssertEqual([claims count], 0, @"claims count != 0"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } - (void)testProverGetClaimsWorksForInvalidWalletHandle @@ -808,6 +824,8 @@ - (void)testProverGetClaimsWorksForInvalidWalletHandle filterJson:@"{}" outClaimsJson:&claimsJson]; XCTAssertEqual(ret.code, WalletInvalidHandle, @"AnoncredsUtils::proverGetClaimsForWalletHandle returned wrong code"); + + [[WalletUtils sharedInstance] closeWalletWithHandle:walletHandle]; } // MARK: - Prover get claims for proof request diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m index d7ba5d5f5c..1053ac8ecd 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m @@ -562,7 +562,7 @@ - (NSError *)initializeCommonWalletAndReturnHandle:(IndyHandle *)walletHandle // 1. Create and open wallet self.walletHandle = 0; IndyHandle tempWalletHandle = 0; - ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:[TestUtils pool] + ret = [[WalletUtils sharedInstance] createAndOpenWalletWithPoolName:@"pool1" xtype:nil handle:&tempWalletHandle]; XCTAssertEqual(ret.code, Success, @"WalletUtils::createAndOpenWalletWithPoolName failed"); From c3958b1cfc5127ba2c55bd1376e98debbf123301 Mon Sep 17 00:00:00 2001 From: mgbailey Date: Fri, 18 Aug 2017 12:34:16 -0600 Subject: [PATCH 19/29] Update ubuntu-build.md --- doc/ubuntu-build.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/ubuntu-build.md b/doc/ubuntu-build.md index 2f6d3cc0ac..a4eff79b59 100644 --- a/doc/ubuntu-build.md +++ b/doc/ubuntu-build.md @@ -16,8 +16,8 @@ 1. Checkout and build the library: ``` - git checkout https://github.com/hyperledger/indy-sdk.git - cd ./indy-sdk + git clone https://github.com/hyperledger/indy-sdk.git + cd ./indy-sdk/libindy cargo build ``` 1. Run integration tests: @@ -55,4 +55,4 @@ RUST_TEST_THREADS=1 TEST_POOL_IP=10.0.0.2 cargo test ``` -See [ci/ubuntu.dockerfile](https://github.com/hyperledger/indy-sdk/tree/master/ci/ubuntu.dockerfile) for example of Ubuntu based environment creation in Docker. \ No newline at end of file +See [ci/ubuntu.dockerfile](https://github.com/hyperledger/indy-sdk/tree/master/ci/ubuntu.dockerfile) for example of Ubuntu based environment creation in Docker. From b2c49f48bc390f1542b958971455cd7027121098 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Mon, 21 Aug 2017 10:24:38 +0300 Subject: [PATCH 20/29] debugging anoncreds tests --- .../Case Tests/Anoncreds/AnoncredsHighCases.m | 2 +- .../libindy-demoTests/Test Utils/AnoncredsUtils.m | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m index aaf22ab3fd..5b31cdf24a 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Anoncreds/AnoncredsHighCases.m @@ -80,7 +80,7 @@ - (void)testIssuerCreateAndStoreClaimDefWorksForInvalidWallet // 2. Create claim definition NSString *schema = [[AnoncredsUtils sharedInstance] getGvtSchemaJson:@(1)]; - IndyHandle invalidWalletHandle = walletHandle + 1; + IndyHandle invalidWalletHandle = walletHandle + 100; ret = [[AnoncredsUtils sharedInstance] issuerCreateClaimDefinifionWithWalletHandle:invalidWalletHandle issuerDid:[AnoncredsUtils issuerDid] schemaJson:schema diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m index 1053ac8ecd..b2f8474f66 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Test Utils/AnoncredsUtils.m @@ -282,7 +282,7 @@ - (NSError *)proverStoreClaimOffer:(IndyHandle)walletHandle completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; NSError *ret = [IndyAnoncreds proverStoreClaimOfferWithWalletHandle:walletHandle - claimOfferJSON:str + claimOfferJSON:str completion: ^(NSError *error) { err = error; @@ -554,8 +554,6 @@ - (NSError *)initializeCommonWalletAndReturnHandle:(IndyHandle *)walletHandle [TestUtils cleanupStorage]; - XCTAssertTrue(5 == 3, @"FALSE!!!!"); - ////TODO Need clean after tests but not exists After function in Cargo NSError *ret; @@ -576,7 +574,7 @@ - (NSError *)initializeCommonWalletAndReturnHandle:(IndyHandle *)walletHandle issuerDid:[AnoncredsUtils issuerDid] schemaJson:schema signatureType:nil - createNonRevoc:false + createNonRevoc:NO claimDefJson:&tempClaimDefJson]; XCTAssertEqual(ret.code, Success, @"issuerCreateClaimDefinifionWithWalletHandle failed"); From 83c6cbb9560f1ecbf18f34fb66b61b75cfdaac26 Mon Sep 17 00:00:00 2001 From: Anastasia Tarasova Date: Mon, 21 Aug 2017 11:55:41 +0300 Subject: [PATCH 21/29] removed misplaced space --- libindy/tests/agent.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindy/tests/agent.rs b/libindy/tests/agent.rs index 254a2332d6..2f71625715 100644 --- a/libindy/tests/agent.rs +++ b/libindy/tests/agent.rs @@ -826,7 +826,7 @@ mod medium_cases { })), None).unwrap(); - AgentUtils::add_identity(listener_handle, pool_handle, wallet_handle, did.as_str()).unwrap(); + AgentUtils::add_identity(listener_handle, pool_handle, wallet_handle, did.as_str()).unwrap(); AgentUtils::connect(0, wallet_handle, did.as_str(), did.as_str(), From 5d02f3d768bdc40c13c5d1f0ceb00cec79c83c75 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 21 Aug 2017 17:53:55 +0300 Subject: [PATCH 22/29] Use snake case for json params --- libindy/include/indy_wallet.h | 2 +- libindy/src/api/pool.rs | 6 +++--- libindy/src/api/wallet.rs | 2 +- libindy/tests/pool.rs | 4 ++-- wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs | 2 +- .../indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs | 2 +- .../libindy-demoTests/Case Tests/Pool/PoolHighCases.m | 2 +- .../libindy-demoTests/Case Tests/Pool/PoolMediumCases.m | 2 +- wrappers/java/README.md | 2 +- .../org/hyperledger/indy/sdk/pool/PoolJSONParameters.java | 6 +++--- wrappers/python/indy/pool.py | 6 +++--- wrappers/python/indy/wallet.py | 2 +- wrappers/python/tests/pool/test_open_pool_ledger.py | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libindy/include/indy_wallet.h b/libindy/include/indy_wallet.h index 9f1531f89c..d2995df2c5 100644 --- a/libindy/include/indy_wallet.h +++ b/libindy/include/indy_wallet.h @@ -98,7 +98,7 @@ extern "C" { /// name: Name of the wallet. /// runtime_config (optional): Runtime wallet configuration json. if NULL, then default runtime_config will be used. Example: /// { - /// "freshnessTime": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60. + /// "freshness_time": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60. /// ... List of additional supported keys are defined by wallet type. /// } /// credentials(optional): Wallet credentials json. List of supported keys are defined by wallet type. diff --git a/libindy/src/api/pool.rs b/libindy/src/api/pool.rs index 75ee8a31c7..28c532a237 100644 --- a/libindy/src/api/pool.rs +++ b/libindy/src/api/pool.rs @@ -56,11 +56,11 @@ pub extern fn indy_create_pool_ledger_config(command_handle: i32, /// config (optional): Runtime pool configuration json. /// if NULL, then default config will be used. Example: /// { -/// "refreshOnOpen": bool (optional), Forces pool ledger to be refreshed immediately after opening. +/// "refresh_on_open": bool (optional), Forces pool ledger to be refreshed immediately after opening. /// Defaults to true. -/// "autoRefreshTime": int (optional), After this time in minutes pool ledger will be automatically refreshed. +/// "auto_refresh_time": int (optional), After this time in minutes pool ledger will be automatically refreshed. /// Use 0 to disable automatic refresh. Defaults to 24*60. -/// "networkTimeout": int (optional), Network timeout for communication with nodes in milliseconds. +/// "network_timeout": int (optional), Network timeout for communication with nodes in milliseconds. /// Defaults to 20000. /// } /// diff --git a/libindy/src/api/wallet.rs b/libindy/src/api/wallet.rs index a512247147..b28ac9694f 100644 --- a/libindy/src/api/wallet.rs +++ b/libindy/src/api/wallet.rs @@ -149,7 +149,7 @@ pub extern fn indy_create_wallet(command_handle: i32, /// name: Name of the wallet. /// runtime_config (optional): Runtime wallet configuration json. if NULL, then default runtime_config will be used. Example: /// { -/// "freshnessTime": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60. +/// "freshness_time": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60. /// ... List of additional supported keys are defined by wallet type. /// } /// credentials(optional): Wallet credentials json. List of supported keys are defined by wallet type. diff --git a/libindy/tests/pool.rs b/libindy/tests/pool.rs index 1636b24bef..ac331df918 100644 --- a/libindy/tests/pool.rs +++ b/libindy/tests/pool.rs @@ -103,7 +103,7 @@ mod high_cases { TestUtils::cleanup_storage(); let pool_name = "open_pool_ledger_works_for_config"; - let config = r#"{"refreshOnOpen": true}"#; + let config = r#"{"refresh_on_open": true}"#; let txn_file_path = PoolUtils::create_genesis_txn_file_for_test_pool(pool_name, None, None); let pool_config = PoolUtils::pool_config_json(txn_file_path.as_path()); @@ -366,7 +366,7 @@ mod medium_cases { fn open_pool_ledger_works_for_invalid_config() { TestUtils::cleanup_storage(); let name = "pool_open"; - let config = r#"{"refreshOnOpen": "true"}"#; + let config = r#"{"refresh_on_open": "true"}"#; let txn_file_path = PoolUtils::create_genesis_txn_file_for_test_pool(name, None, None); let pool_config = PoolUtils::pool_config_json(txn_file_path.as_path()); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs b/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs index d48ca2e125..7636b77ca5 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs @@ -67,7 +67,7 @@ public static void CreatePoolLedgerConfig(string poolName, int nodesCnt) public static async Task CreateAndOpenPoolLedgerAsync() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - var openPoolLedgerConfig = "{\"refreshOnOpen\":true}"; + var openPoolLedgerConfig = "{\"refresh_on_open\":true}"; return await Pool.OpenPoolLedgerAsync(poolName, openPoolLedgerConfig); } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs index 67f6c52497..7e0630f0d7 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs @@ -23,7 +23,7 @@ public async Task TestOpenPoolWorksForConfig() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - var config = "{\"refreshOnOpen\":true,\"autoRefreshTime\":false,\"networkTimeout\":false}"; + var config = "{\"refresh_on_open\":true,\"auto_refresh_time\":false,\"network_timeout\":false}"; var pool = await Pool.OpenPoolLedgerAsync(poolName, config); diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolHighCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolHighCases.m index c20e1eee0c..64cabc83d7 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolHighCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolHighCases.m @@ -107,7 +107,7 @@ - (void) testOpenPoolLedgerWorks // [TestUtils cleanupStorage]; // // NSString *poolName = @"open_pool_ledger_works_for_config"; -// NSString *config = @"{\"refreshOnOpen\": true}"; +// NSString *config = @"{\"refresh_on_open\": true}"; // // // 1. Create pool ledger config // NSError *ret = [[PoolUtils sharedInstance] createPoolLedgerConfigWithPoolName:poolName diff --git a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolMediumCases.m b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolMediumCases.m index 62ce66b70c..184bb8d12f 100644 --- a/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolMediumCases.m +++ b/wrappers/ios/libindy-pod/libindy-demoTests/Case Tests/Pool/PoolMediumCases.m @@ -140,7 +140,7 @@ - (void)testOpenPoolLedgerWorksForWrongAlias //{ // [TestUtils cleanupStorage]; // NSString *poolName = @"pool_open"; -// NSString *config = @"{\"refreshOnOpen\": \"true\"}"; +// NSString *config = @"{\"refresh_on_open\": \"true\"}"; // // // 1. create pool ledger // NSError *ret = [[PoolUtils sharedInstance] createPoolLedgerConfigWithPoolName:poolName diff --git a/wrappers/java/README.md b/wrappers/java/README.md index 9bc46418d7..026ed2b3db 100644 --- a/wrappers/java/README.md +++ b/wrappers/java/README.md @@ -117,7 +117,7 @@ Output: CreatePoolLedgerConfigJSONParameter: {"genesis_txn":"localhost.txn"} CreatePoolLedgerConfigResult: PoolResults.CreatePoolLedgerConfigResult[] === OPEN POOL === - OpenPoolLedgerJSONParameter: {"refreshOnOpen":true} + OpenPoolLedgerJSONParameter: {"refresh_on_open":true} OpenPoolLedgerResult: PoolResults.OpenPoolLedgerResult[pool=Pool[poolHandle=2]] === CREATE TRUSTEE WALLET === CreateWalletResultTrustee: WalletResults.CreateWalletResult[] diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolJSONParameters.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolJSONParameters.java index 7f6cba9249..72e3f84130 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolJSONParameters.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolJSONParameters.java @@ -23,9 +23,9 @@ public static class OpenPoolLedgerJSONParameter extends IndyJava.JsonParameter { public OpenPoolLedgerJSONParameter(Boolean refreshOnOpen, Boolean autoRefreshTime, Integer networkTimeout) { - if (refreshOnOpen != null) this.map.put("refreshOnOpen", refreshOnOpen); - if (autoRefreshTime != null) this.map.put("autoRefreshTime", autoRefreshTime); - if (networkTimeout != null) this.map.put("networkTimeout", networkTimeout); + if (refreshOnOpen != null) this.map.put("refresh_on_open", refreshOnOpen); + if (autoRefreshTime != null) this.map.put("auto_refresh_time", autoRefreshTime); + if (networkTimeout != null) this.map.put("network_timeout", networkTimeout); } } } diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index eb464bfe05..c1279f9e65 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -54,11 +54,11 @@ async def open_pool_ledger(config_name: str, :param config: (optional) Runtime pool configuration json. if NULL, then default config will be used. Example: { - "refreshOnOpen": bool (optional), Forces pool ledger to be refreshed immediately after opening. + "refresh_on_open": bool (optional), Forces pool ledger to be refreshed immediately after opening. Defaults to true. - "autoRefreshTime": int (optional), After this time in minutes pool ledger will be automatically refreshed. + "auto_refresh_time": int (optional), After this time in minutes pool ledger will be automatically refreshed. Use 0 to disable automatic refresh. Defaults to 24*60. - "networkTimeout": int (optional), Network timeout for communication with nodes in milliseconds. + "network_timeout": int (optional), Network timeout for communication with nodes in milliseconds. Defaults to 20000. } :return: Handle to opened pool to use in methods that require pool connection. diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index 55f8a32f71..83a1dd0984 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -66,7 +66,7 @@ async def open_wallet(name: str, :param runtime_config: (optional) Runtime wallet configuration json. if NULL, then default runtime_config will be used. Example: { - "freshnessTime": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60. + "freshness_time": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60. ... List of additional supported keys are defined by wallet type. } :param credentials: (optional) Wallet credentials json. List of supported keys are defined by wallet type. diff --git a/wrappers/python/tests/pool/test_open_pool_ledger.py b/wrappers/python/tests/pool/test_open_pool_ledger.py index 3eab793d5d..0cf25770af 100644 --- a/wrappers/python/tests/pool/test_open_pool_ledger.py +++ b/wrappers/python/tests/pool/test_open_pool_ledger.py @@ -6,7 +6,7 @@ @pytest.mark.parametrize( "pool_genesis_txn_count, pool_config", - [(2, None), (3, None), (4, None), (4, '{"refreshOnOpen": true}')]) + [(2, None), (3, None), (4, None), (4, '{"refresh_on_open": true}')]) @pytest.mark.asyncio async def test_open_pool_ledger_works(pool_handle): pass From 52e26c9ccbd8af2533d24df717c7d09a4b35bdc7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Tue, 22 Aug 2017 10:06:25 +0300 Subject: [PATCH 23/29] * Added document describes planned CI/CD pipeline --- doc/cd-pipeline.puml | 139 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 doc/cd-pipeline.puml diff --git a/doc/cd-pipeline.puml b/doc/cd-pipeline.puml new file mode 100644 index 0000000000..9ab01af433 --- /dev/null +++ b/doc/cd-pipeline.puml @@ -0,0 +1,139 @@ +@startuml + +start + +partition Testing { + fork + partition "Ubuntu Testing" { + :Start test pool; + if (BRANCH_NAME in ["master", "rc"]) then (yes) + :Libindy\nRelease build; + else (no) + :Libindy\nDebug build; + endif + :Libindy + Testing; + :Python Wrapper + Testing; + :Java Wrapper + Testing; + } + fork again + partition "RHEL Testing" { + :Start test pool; + if (BRANCH_NAME in ["master", "rc"]) then (yes) + :Libindy\nRelease build; + else (no) + :Libindy\nDebug build; + endif + :Libindy + Testing; + :Python Wrapper + Testing; + :Java Wrapper + Testing; + } + fork again + partition "Windows Testing" { + :Start test pool; + if (BRANCH_NAME in ["master", "rc"]) then (yes) + :Libindy\nRelease build; + else (no) + :Libindy\nDebug build; + endif + :Libindy + Testing; + :Python Wrapper + Testing; + :Java Wrapper + Testing; + #red:.Net Wrapper + Testing; + note right: Not implemented yet\nSee IS-257 + } + fork again + partition "MacOS Testing" { + #red::Skip; + note right: Not implemented yet\nSee IS-192 + } + fork again + partition "iOS Testing" { + #red::Skip; + note right: Not implemented yet\nSee IS-189 + } + end fork +} + +partition Publishing { + if (BRANCH_NAME in ["master", "rc"]) then (yes) + fork + partition "Ubuntu Publishing" { + :Libindy + Build and publish Master(RC) debs; + :Python Wrapper + Publish RC to PyPi; + :Java Wrapper + Build and publish RC to Maven Central; + } + fork again + partition "RHEL Publishing" { + :Libindy + Build and publish RC rpms; + } + fork again + partition "Windows Publishing" { + :Libindy + Build and publish RC dlls archive; + #red:.Net Wrapper + RC Publishing; + note right: Not implemented yet\nSee IS-306 + } + fork again + partition "MacOS Publishing" { + #red::Skip; + note right: Not implemented yet\nSee IS-6 + } + fork again + partition "iOS Publishing" { + #red::Skip; + note right: Not implemented yet\nSee IS-100 + } + end fork + else (no) + :Skip publishing; + endif +} + +partition "Acceptance Testing" { + if (BRANCH_NAME == "rc") then (yes) + :Notify QA about new artifacts to test; + :Acceptance testing by QA; + else (no) + :Skip Acceptance Testing; + endif +} + +partition "Releasing" { + if (BRANCH_NAME == "rc" && Acceptance tests passed) then (yes) + :Libindy + Move RC debs to Stable repo; + :Libindy + Move RC rmps to Stable repo; + :Libindy + Move RC dlls archive to Stable repo; + :Python Wrapper + Publish Stable to PyPi; + :Java Wrapper + Build and publish Stable to Maven Central; + else (no) + :Skip Releasing; + endif +} + +partition Notification { + :Notify team about pipeline result; +} + +stop + +@enduml From 5808b3e56a5bd1190954aabfe165813357c6a056 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 22 Aug 2017 11:04:00 +0300 Subject: [PATCH 24/29] Added TRUST_ANCHOR Role in Build_nym_request --- libindy/src/services/ledger/constants.rs | 1 + libindy/src/services/ledger/mod.rs | 1 + libindy/src/services/ledger/types.rs | 4 ++- libindy/tests/ledger.rs | 34 +++++++++++++++++-- .../tests/ledger/test_build_nym_request.py | 33 +++++++++++++++++- 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/libindy/src/services/ledger/constants.rs b/libindy/src/services/ledger/constants.rs index 1bf8145391..7c7cf6f879 100644 --- a/libindy/src/services/ledger/constants.rs +++ b/libindy/src/services/ledger/constants.rs @@ -12,3 +12,4 @@ pub const GET_DDO: &'static str = "120";//TODO change number pub const STEWARD: isize = 2; pub const TRUSTEE: isize = 0; +pub const TRUST_ANCHOR: isize = 101; diff --git a/libindy/src/services/ledger/mod.rs b/libindy/src/services/ledger/mod.rs index 1038df814b..98874cf4ea 100644 --- a/libindy/src/services/ledger/mod.rs +++ b/libindy/src/services/ledger/mod.rs @@ -51,6 +51,7 @@ impl LedgerService { match r.clone() { "STEWARD" => Some(Role::STEWARD as i32), "TRUSTEE" => Some(Role::TRUSTEE as i32), + "TRUST_ANCHOR" => Some(Role::TrustAnchor as i32), role @ _ => return Err(CommonError::InvalidStructure(format!("Invalid role: {}", role))) }, _ => None diff --git a/libindy/src/services/ledger/types.rs b/libindy/src/services/ledger/types.rs index 884c2da334..4e6af8e936 100644 --- a/libindy/src/services/ledger/types.rs +++ b/libindy/src/services/ledger/types.rs @@ -15,6 +15,7 @@ use services::ledger::constants::{ GET_CLAIM_DEF, STEWARD, TRUSTEE, + TRUST_ANCHOR, GET_TXN }; @@ -44,7 +45,8 @@ impl JsonEncodable for Request {} #[derive(Deserialize, Serialize, PartialEq, Debug)] pub enum Role { STEWARD = STEWARD, - TRUSTEE = TRUSTEE + TRUSTEE = TRUSTEE, + TrustAnchor = TRUST_ANCHOR } #[derive(Serialize, PartialEq, Debug)] diff --git a/libindy/tests/ledger.rs b/libindy/tests/ledger.rs index 3e6e7a35ee..4cdc6a466e 100644 --- a/libindy/tests/ledger.rs +++ b/libindy/tests/ledger.rs @@ -39,7 +39,7 @@ use utils::types::{ GetTxnResult, SchemaData }; -use std::collections::{HashSet}; +use std::collections::HashSet; // TODO: FIXME: create_my_did doesn't support CID creation, but this trustee has CID as DID. So it is rough workaround for this issue. // See: https://github.com/hyperledger/indy-sdk/issues/25 @@ -1002,7 +1002,7 @@ mod medium_cases { let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); - let role = "STEWARD"; + let role = "TRUST_ANCHOR"; let alias = "some_alias"; let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey), Some(alias), Some(role)).unwrap(); @@ -1012,6 +1012,36 @@ mod medium_cases { TestUtils::cleanup_storage(); } + #[test] + #[cfg(feature = "local_nodes_pool")] + fn indy_send_nym_request_works_for_different_roles() { + TestUtils::cleanup_storage(); + + let pool_name = "indy_send_nym_request_works_for_different_roles"; + + let pool_handle = PoolUtils::create_and_open_pool_ledger(pool_name).unwrap(); + let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); + + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); + let role = "STEWARD"; + let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, Some(role)).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + + let (my_did2, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); + let role = "TRUSTEE"; + let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did2.clone(), None, None, Some(role)).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + + let (my_did3, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); + let role = "TRUST_ANCHOR"; + let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did3.clone(), None, None, Some(role)).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + + TestUtils::cleanup_storage(); + } + #[test] #[cfg(feature = "local_nodes_pool")] fn indy_build_nym_requests_works_for_wrong_role() { diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index 66557c768d..adb3057520 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -1,4 +1,4 @@ -from indy import ledger +from indy import ledger, signus from indy.error import ErrorCode, IndyError import json @@ -53,3 +53,34 @@ async def test_build_nym_request_works_with_option_fields(): response = json.loads(await ledger.build_nym_request(identifier, destination, ver_key, alias, role)) assert expected_response.items() <= response.items() + + +@pytest.mark.asyncio +async def test_nym_request_works_for_different_roles(wallet_handle, pool_handle, identity_trustee1): + (trustee_did, _) = identity_trustee1 + + await check_for_role(pool_handle, wallet_handle, trustee_did, 'TRUST_ANCHOR', '101') + await check_for_role(pool_handle, wallet_handle, trustee_did, 'TRUSTEE', '0') + await check_for_role(pool_handle, wallet_handle, trustee_did, 'STEWARD', '2') + + +@pytest.mark.asyncio +async def check_for_role(pool_handle, wallet_handle, trustee_did, role, expected_role_value): + (my_did, my_verkey, _) = await signus.create_and_store_my_did(wallet_handle, "{}") + + nym_request = await ledger.build_nym_request(trustee_did, my_did, my_verkey, None, role) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) + + get_nym_request = await ledger.build_get_nym_request(my_did, my_did) + get_nym_response = json.loads(await ledger.submit_request(pool_handle, get_nym_request)) + assert expected_role_value == json.loads(get_nym_response['result']['data'])['role'] + + +@pytest.mark.asyncio +async def test_nym_request_works_for_invalid_role(identity_trustee1, identity_my1): + (trustee_did, _) = identity_trustee1 + (my_did, _) = identity_my1 + + with pytest.raises(IndyError) as e: + await ledger.build_nym_request(trustee_did, my_did, None, None, "WRONG_ROLE") + assert ErrorCode.CommonInvalidStructure == e.value.error_code From 9909a5bb10e45d22414699ffd0daa0186bf26f35 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 22 Aug 2017 11:06:14 +0300 Subject: [PATCH 25/29] Retunred role --- libindy/tests/ledger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindy/tests/ledger.rs b/libindy/tests/ledger.rs index 4cdc6a466e..24c7373658 100644 --- a/libindy/tests/ledger.rs +++ b/libindy/tests/ledger.rs @@ -1002,7 +1002,7 @@ mod medium_cases { let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); - let role = "TRUST_ANCHOR"; + let role = "STEWARD"; let alias = "some_alias"; let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey), Some(alias), Some(role)).unwrap(); From 27f8d7cb0c43941b870a9b61936428b718e8fec3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Tue, 22 Aug 2017 11:37:05 +0300 Subject: [PATCH 26/29] * Minor fixes --- doc/cd-pipeline.puml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/cd-pipeline.puml b/doc/cd-pipeline.puml index 9ab01af433..28370ce49d 100644 --- a/doc/cd-pipeline.puml +++ b/doc/cd-pipeline.puml @@ -69,11 +69,11 @@ partition Publishing { fork partition "Ubuntu Publishing" { :Libindy - Build and publish Master(RC) debs; + Build and publish Master/RC debs; :Python Wrapper Publish RC to PyPi; :Java Wrapper - Build and publish RC to Maven Central; + Build and publish Master/RC to Maven Central; } fork again partition "RHEL Publishing" { @@ -83,9 +83,9 @@ partition Publishing { fork again partition "Windows Publishing" { :Libindy - Build and publish RC dlls archive; + Build and publish Master/RC dlls archive; #red:.Net Wrapper - RC Publishing; + Master/RC Publishing; note right: Not implemented yet\nSee IS-306 } fork again From 6259ccbe0300e2ff96a95baf123a1890c4f8d9f1 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 22 Aug 2017 11:53:19 +0300 Subject: [PATCH 27/29] Reverted changes in Python wrapper --- .../tests/ledger/test_build_nym_request.py | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index adb3057520..3995ea6db2 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -53,34 +53,3 @@ async def test_build_nym_request_works_with_option_fields(): response = json.loads(await ledger.build_nym_request(identifier, destination, ver_key, alias, role)) assert expected_response.items() <= response.items() - - -@pytest.mark.asyncio -async def test_nym_request_works_for_different_roles(wallet_handle, pool_handle, identity_trustee1): - (trustee_did, _) = identity_trustee1 - - await check_for_role(pool_handle, wallet_handle, trustee_did, 'TRUST_ANCHOR', '101') - await check_for_role(pool_handle, wallet_handle, trustee_did, 'TRUSTEE', '0') - await check_for_role(pool_handle, wallet_handle, trustee_did, 'STEWARD', '2') - - -@pytest.mark.asyncio -async def check_for_role(pool_handle, wallet_handle, trustee_did, role, expected_role_value): - (my_did, my_verkey, _) = await signus.create_and_store_my_did(wallet_handle, "{}") - - nym_request = await ledger.build_nym_request(trustee_did, my_did, my_verkey, None, role) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) - - get_nym_request = await ledger.build_get_nym_request(my_did, my_did) - get_nym_response = json.loads(await ledger.submit_request(pool_handle, get_nym_request)) - assert expected_role_value == json.loads(get_nym_response['result']['data'])['role'] - - -@pytest.mark.asyncio -async def test_nym_request_works_for_invalid_role(identity_trustee1, identity_my1): - (trustee_did, _) = identity_trustee1 - (my_did, _) = identity_my1 - - with pytest.raises(IndyError) as e: - await ledger.build_nym_request(trustee_did, my_did, None, None, "WRONG_ROLE") - assert ErrorCode.CommonInvalidStructure == e.value.error_code From 99ae0a72e2f0f294f1b35ad352475a63adf0c9ed Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Tue, 22 Aug 2017 12:17:56 +0300 Subject: [PATCH 28/29] * Minor fixes --- doc/cd-pipeline.puml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/cd-pipeline.puml b/doc/cd-pipeline.puml index 28370ce49d..fcfa88e227 100644 --- a/doc/cd-pipeline.puml +++ b/doc/cd-pipeline.puml @@ -2,6 +2,9 @@ start +title Indy SDK CI/CD Pipeline structure +scale 0.8 + partition Testing { fork partition "Ubuntu Testing" { @@ -78,7 +81,7 @@ partition Publishing { fork again partition "RHEL Publishing" { :Libindy - Build and publish RC rpms; + Build and publish Master/RC rpms; } fork again partition "Windows Publishing" { From 360978c7c0908a4d8153c195afb61bf6173e2d6a Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 22 Aug 2017 13:25:38 +0300 Subject: [PATCH 29/29] Use CamelCase for Enum --- libindy/src/services/ledger/mod.rs | 4 ++-- libindy/src/services/ledger/types.rs | 4 ++-- wrappers/python/tests/ledger/test_build_nym_request.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libindy/src/services/ledger/mod.rs b/libindy/src/services/ledger/mod.rs index 98874cf4ea..f9381dc29a 100644 --- a/libindy/src/services/ledger/mod.rs +++ b/libindy/src/services/ledger/mod.rs @@ -49,8 +49,8 @@ impl LedgerService { let role = match role { Some(r) => match r.clone() { - "STEWARD" => Some(Role::STEWARD as i32), - "TRUSTEE" => Some(Role::TRUSTEE as i32), + "STEWARD" => Some(Role::Steward as i32), + "TRUSTEE" => Some(Role::Trustee as i32), "TRUST_ANCHOR" => Some(Role::TrustAnchor as i32), role @ _ => return Err(CommonError::InvalidStructure(format!("Invalid role: {}", role))) }, diff --git a/libindy/src/services/ledger/types.rs b/libindy/src/services/ledger/types.rs index 4e6af8e936..00424d760e 100644 --- a/libindy/src/services/ledger/types.rs +++ b/libindy/src/services/ledger/types.rs @@ -44,8 +44,8 @@ impl JsonEncodable for Request {} #[derive(Deserialize, Serialize, PartialEq, Debug)] pub enum Role { - STEWARD = STEWARD, - TRUSTEE = TRUSTEE, + Steward = STEWARD, + Trustee = TRUSTEE, TrustAnchor = TRUST_ANCHOR } diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index 3995ea6db2..66557c768d 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -1,4 +1,4 @@ -from indy import ledger, signus +from indy import ledger from indy.error import ErrorCode, IndyError import json