-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicHTTPAuthAccountTest.m
97 lines (72 loc) · 4.31 KB
/
BasicHTTPAuthAccountTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// BopplAccountTest.m
// BopplExample
//
// Created by Davide De Franceschi on 20/08/14.
// Copyright (c) 2014 Davide De Franceschi. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "BasicHTTPAuthAccount.h"
@interface BasicHTTPAuthAccountTest : XCTestCase
@property (strong, nonatomic) BasicHTTPAuthAccount *exampleAccount;
@property (strong, nonatomic) BasicHTTPAuthAccount *exampleInvalidAccount;
@property (strong, nonatomic) NSString *exampleInvalidAccountEncodedAuthorizationString;
@end
@implementation BasicHTTPAuthAccountTest
#pragma mark XCTestCase
- (void)setUp
{
[super setUp];
self.exampleAccount = [BasicHTTPAuthAccount accountWithUsername:@"[email protected]" andPassword:@"password123"];
self.exampleInvalidAccount = [BasicHTTPAuthAccount accountWithUsername:@"[email protected]" andPassword:@"password"];
self.exampleInvalidAccountEncodedAuthorizationString = @"dGVzdEBleGFtcGxlLmNvbTpwYXNzd29yZA==";
}
#pragma mark BopplAccountTest
- (void)testAccountWithValidCredentials
{
BasicHTTPAuthAccount *testAccount;
testAccount = [BasicHTTPAuthAccount accountWithUsername:self.exampleInvalidAccount.username andPassword:self.exampleInvalidAccount.password];
XCTAssertNotNil(testAccount, @"Should have returned a not nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithEncodedAuthorizationString:self.exampleInvalidAccountEncodedAuthorizationString];
XCTAssertNotNil(testAccount, @"Should have returned a not nil BopplAccount.");
}
- (void)testAccountWithInvalidCredentials
{
BasicHTTPAuthAccount *testAccount;
testAccount = [BasicHTTPAuthAccount accountWithUsername:nil andPassword:nil];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithUsername:nil andPassword:@""];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithUsername:@"" andPassword:nil];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithUsername:@"" andPassword:@""];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithUsername:self.exampleInvalidAccount.username andPassword:nil];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithUsername:self.exampleInvalidAccount.username andPassword:@""];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithUsername:nil andPassword:self.exampleInvalidAccount.password];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithUsername:@"" andPassword:self.exampleInvalidAccount.password];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithEncodedAuthorizationString:nil];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
testAccount = [BasicHTTPAuthAccount accountWithEncodedAuthorizationString:@""];
XCTAssertNil(testAccount, @"Should have returned a nil BopplAccount.");
}
- (void)testBase64ValidEncodingAndDecoding
{
NSString *encodedString = [self.exampleInvalidAccount encodedAuthorizationString];
XCTAssertNotNil(encodedString, @"Should have returned a not nil encodedString.");
XCTAssertEqualObjects(encodedString, self.exampleInvalidAccountEncodedAuthorizationString, @"The encoded string should be equal to the precomputed one.");
BasicHTTPAuthAccount *testAccount = [BasicHTTPAuthAccount accountWithEncodedAuthorizationString:encodedString];
XCTAssertEqualObjects(testAccount, self.exampleInvalidAccount, @"The reconstructed account should be equal to the starting one.");
}
- (void)testBase64InvalidEncodingAndDecoding
{
NSString *encodedString = [self.exampleAccount encodedAuthorizationString];
XCTAssertNotEqualObjects(encodedString, self.exampleInvalidAccountEncodedAuthorizationString, @"The encoded string should be different from the precomputed one.");
BasicHTTPAuthAccount *testAccount = [BasicHTTPAuthAccount accountWithEncodedAuthorizationString:encodedString];
XCTAssertNotEqualObjects(testAccount, self.exampleInvalidAccount, @"The reconstructed account should be different from the starting one.");
}
@end