Skip to content

Commit

Permalink
Delete Logs and increase code cov
Browse files Browse the repository at this point in the history
  • Loading branch information
m-stephen committed Apr 3, 2019
1 parent faf1aeb commit 4a82dcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
7 changes: 1 addition & 6 deletions MapboxMobileEvents/MMECertPin.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,13 @@ - (NSData *)hashSubjectPublicKeyInfoFromCertificate:(SecCertificateRef)certifica

if (cachedSubjectPublicKeyInfo)
{
NSLog(@"Subject Public Key Info hash was found in the cache");
return cachedSubjectPublicKeyInfo;
}

// We didn't this certificate in the cache
NSLog(@"Generating Subject Public Key Info hash...");

// We didn't have this certificate in the cache
// First extract the public key bytes
NSData *publicKeyData = [self getPublicKeyDataFromCertificate:certificate];
if (publicKeyData == nil){
NSLog(@"Error - could not extract the public key bytes");
return nil;
}

Expand Down Expand Up @@ -273,7 +269,6 @@ - (NSData *)getPublicKeyDataFromCertificate_legacy_ios:(SecCertificateRef)certif
if ((resultAdd != errSecSuccess) || (resultDel != errSecSuccess))
{
// Something went wrong with the Keychain we won't know if we did get the right key data
NSLog(@"Keychain error");
publicKeyData = nil;
}

Expand Down
21 changes: 14 additions & 7 deletions MapboxMobileEventsTests/MMECertPinTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
#import "MMECertPin.h"
#import "MMEEventsConfiguration.h"
#import "MMEPinningConfigurationProvider.h"
#import "MMENSURLSessionWrapper.h"

using namespace Cedar::Matchers;
using namespace Cedar::Doubles;

@interface MMENSURLSessionWrapper (MMECertPinTests)

@property (nonatomic) MMECertPin *certPin;

@end

@interface MMECertPin (Tests)

@property (nonatomic) MMEPinningConfigurationProvider *pinningConfigProvider;
Expand All @@ -17,41 +24,41 @@ @interface MMECertPin (Tests)

describe(@"MMECertPin", ^{

__block MMECertPin *certPin;
__block MMENSURLSessionWrapper *sessionWrapper;
__block MMEEventsConfiguration *configuration;
__block NSArray *blacklistFake;

beforeEach(^{
configuration = [MMEEventsConfiguration configuration];
certPin = [[MMECertPin alloc] init];
sessionWrapper.certPin = [[MMECertPin alloc] init];
blacklistFake = [NSArray arrayWithObjects:@"i/4rsupujT8Ww/2yIGJ3wb6R7GDw2FHPyOM5sWh87DQ=", @"+1CHLRDE6ehp61cm8+NDMvd32z0Qc4bgnZRLH0OjE94=", nil];
configuration.blacklist = blacklistFake;
});

it(@"should have china hash array with a count of 54", ^{
NSArray *cnHashes = certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.cn"][kMMEPublicKeyHashes];
NSArray *cnHashes = sessionWrapper.certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.cn"][kMMEPublicKeyHashes];
cnHashes.count should equal(54);
});

it(@"should have .com hash array with a count of 54", ^{
NSArray *comHashes = certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.com"][kMMEPublicKeyHashes];
NSArray *comHashes = sessionWrapper.certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.com"][kMMEPublicKeyHashes];
comHashes.count should equal(54);
});

describe(@"- updateHashesWithConfiguration", ^{
beforeEach(^{
[certPin updateWithConfiguration:configuration];
[sessionWrapper reconfigure:configuration];
});

context(@"when hashes have been updated", ^{

it(@"should remove blacklisted hashes from .cnHashes", ^{
NSArray *cnHashes = certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.cn"][kMMEPublicKeyHashes];
NSArray *cnHashes = sessionWrapper.certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.cn"][kMMEPublicKeyHashes];
cnHashes.count should equal(53);
});

it(@"should remove blacklisted hashes from .comHashes", ^{
NSArray *comHashes = certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.com"][kMMEPublicKeyHashes];
NSArray *comHashes = sessionWrapper.certPin.pinningConfigProvider.pinningConfig[kMMEPinnedDomains][@"events.mapbox.com"][kMMEPublicKeyHashes];
comHashes.count should equal(53);
});
});
Expand Down

0 comments on commit 4a82dcf

Please sign in to comment.