Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3a623dd87a
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (61 sloc) 2.242 kb
//
// PKWebSocketCryptoTests.m
// PKWebSocket
//
// Created by Pavel Kunc on 17/04/2012.
// Copyright (c) 2012 Pavel Kunc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <SenTestingKit/SenTestingKit.h>
#import "PKWebSocketCrypto.h"
@interface PKWebSocketCryptoTests : SenTestCase
@end
@implementation PKWebSocketCryptoTests
- (void)setUp {
[super setUp];
}
- (void)tearDown {
[super tearDown];
}
#pragma mark - Tests
- (void)testHixie76KeyIsString {
SecKey secKey = pkws_hixie76Key();
STAssertTrue([secKey.key isKindOfClass:[NSString class]],
@"Security Key must be a string");
}
- (void)testHixie76KeyDoesNotStartOrEndWithSpace {
SecKey secKey = pkws_hixie76Key();
STAssertTrue([secKey.key characterAtIndex:0] != ' ',
@"First character must not be blank");
STAssertTrue([secKey.key characterAtIndex:[secKey.key length]-1] != ' ',
@"Last character must not be blank");
}
- (void)testHixie76KeyMustHaveSpaces {
SecKey secKey = pkws_hixie76Key();
NSUInteger spaces = 0;
for (NSUInteger i = 0; i < [secKey.key length]; i++) {
if ([secKey.key characterAtIndex:i] == 0x20) spaces++;
}
STAssertTrue(spaces > 0, @"Key must have some spaces");
}
- (void)testHixie76KeyMustCorretNubmerOfSpacesAndSpecialCharacters {
SecKey secKey = pkws_hixie76Key();
NSUInteger spaces = 0;
NSUInteger digits = 0;
for (NSUInteger i = 0; i < [secKey.key length]; i++) {
char character = [secKey.key characterAtIndex:i];
if (character == ' ') spaces++;
if (character >= '0' && character <= '9') digits++;
}
STAssertTrue(digits % spaces == 0,
@"As per 5.2.6, abort if numbers (%d) is not an integral multiple of spaces (%d)", digits, spaces);
STAssertTrue([secKey.key length] - spaces - digits == 12,
@"We decided to inject 12 characters into our keys so we should have them.");
}
- (void)testRandomDataReturnsDataOfCorrectLength {
NSUInteger length = 8;
NSData *data = [NSData pk_randomBytesOfLength:length];
STAssertTrue([data length] == length,
@"We asked for data of length and got different length.");
}
@end
Jump to Line
Something went wrong with that request. Please try again.