-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ios secure comparator tests (#288)
* add secure comparator tests * tests clean up * update objc example to illustrate SComparator * add sconparator swift tests * add swift scomparator code * re-link podifle lock to the latest master
- Loading branch information
Showing
15 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../examples/objc/ThemisTest/ThemisTest.xcodeproj/xcshareddata/xcschemes/ThemisTest.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mples/swift/ThemisSwift/ThemisSwift.xcodeproj/xcshareddata/xcschemes/ThemisSwift.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// SecureComparatorTests.m | ||
// objthemis | ||
// | ||
// Created by Anastasiia on 1/19/18. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import <objcthemis/objcthemis.h> | ||
|
||
|
||
#define SECURE_COMPARATOR_ENABLED | ||
#import <objcthemis/scomparator.h> | ||
|
||
|
||
@interface SecureComparatorTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation SecureComparatorTests | ||
|
||
- (void)testSecureComparatorEqualMessage { | ||
NSString * sharedSecret = @"shared secret"; | ||
NSData * sharedSecretData = [sharedSecret dataUsingEncoding:NSUTF8StringEncoding]; | ||
TSComparator * alice = [[TSComparator alloc] initWithMessageToCompare:sharedSecretData]; | ||
TSComparator * bob = [[TSComparator alloc] initWithMessageToCompare:sharedSecretData]; | ||
NSError * error = nil; | ||
|
||
NSData * data = [alice beginCompare:&error]; | ||
while ([alice status] == TSComparatorNotReady || [bob status] == TSComparatorNotReady) { | ||
data = [bob proceedCompare:data error:&error]; | ||
data = [alice proceedCompare:data error:&error]; | ||
} | ||
|
||
XCTAssertNil(error, @"result of comparison should be successful"); | ||
XCTAssertEqual([alice status], TSComparatorMatch, @"comparison should match"); | ||
XCTAssertEqual([bob status], TSComparatorMatch, @"comparison should match"); | ||
} | ||
|
||
- (void)testSecureComparatorDifferentMessage { | ||
TSComparator * alice = [[TSComparator alloc] initWithMessageToCompare:[@"some secret" dataUsingEncoding:NSUTF8StringEncoding]]; | ||
TSComparator * bob = [[TSComparator alloc] initWithMessageToCompare:[@"another secret" dataUsingEncoding:NSUTF8StringEncoding]]; | ||
NSError * error = nil; | ||
|
||
NSData * data = [alice beginCompare:&error]; | ||
while ([alice status] == TSComparatorNotReady || [bob status] == TSComparatorNotReady) { | ||
data = [bob proceedCompare:data error:&error]; | ||
data = [alice proceedCompare:data error:&error]; | ||
} | ||
|
||
XCTAssertNil(error, @"result of comparison should be successful"); | ||
XCTAssertEqual([alice status], TSComparatorNotMatch, @"comparison should not match"); | ||
XCTAssertEqual([bob status], TSComparatorNotMatch, @"comparison should not match"); | ||
} | ||
|
||
|
||
@end |
44 changes: 44 additions & 0 deletions
44
tests/objcthemis/objthemis/SecureComparatorTestsSwift.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// SecureComparatorTestsSwift.swift | ||
// objthemis | ||
// | ||
// Created by Anastasiia on 1/19/18. | ||
// | ||
|
||
import XCTest | ||
|
||
class SecureComparatorTestsSwift: XCTestCase { | ||
|
||
func testSecureComparatorEqualMessage() { | ||
|
||
let sharedMessage = "shared secret" | ||
let alice: TSComparator = TSComparator.init(messageToCompare: sharedMessage.data(using: .utf8)!)! | ||
let bob: TSComparator = TSComparator.init(messageToCompare: sharedMessage.data(using: .utf8)!)! | ||
|
||
var data = try? alice.beginCompare() | ||
|
||
while (alice.status() == TSComparatorStateType.notReady || bob.status() == TSComparatorStateType.notReady ) { | ||
data = try? bob.proceedCompare(data) | ||
data = try? alice.proceedCompare(data) | ||
} | ||
|
||
XCTAssertEqual(alice.status(), TSComparatorStateType.match, "comparison should match") | ||
XCTAssertEqual(bob.status(), TSComparatorStateType.match, "comparison should match") | ||
} | ||
|
||
func testSecureComparatorDifferentMessage() { | ||
let alice: TSComparator = TSComparator.init(messageToCompare: "one secret".data(using: .utf8)!)! | ||
let bob: TSComparator = TSComparator.init(messageToCompare: "another secret".data(using: .utf8)!)! | ||
|
||
var data = try? alice.beginCompare() | ||
|
||
while (alice.status() == TSComparatorStateType.notReady || bob.status() == TSComparatorStateType.notReady ) { | ||
data = try? bob.proceedCompare(data) | ||
data = try? alice.proceedCompare(data) | ||
} | ||
|
||
XCTAssertEqual(alice.status(), TSComparatorStateType.notMatch, "comparison should not match") | ||
XCTAssertEqual(bob.status(), TSComparatorStateType.notMatch, "comparison should not match") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters