Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding crypto tests.

  • Loading branch information...
commit 4ca4d563412e733dae9e6f915dfbae7650035879 1 parent f188e4c
@pk authored
View
16 PKWebSocket.xcodeproj/project.pbxproj
@@ -40,6 +40,7 @@
E994C283153C3DF10078AA11 /* libPKWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E994C26B153C3DF00078AA11 /* libPKWebSocket.a */; };
E994C289153C3DF10078AA11 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E994C287153C3DF10078AA11 /* InfoPlist.strings */; };
E994C28C153C3DF10078AA11 /* PKWebSocketTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E994C28B153C3DF10078AA11 /* PKWebSocketTests.m */; };
+ E9B6D9C71544A9B600DF3D4A /* PKWebSocketCryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E9B6D9C61544A9B600DF3D4A /* PKWebSocketCryptoTests.m */; };
E9CCF385154172390019878B /* PKWebSocketFrameParser-Hixie76.h in Headers */ = {isa = PBXBuildFile; fileRef = E9CCF383154172390019878B /* PKWebSocketFrameParser-Hixie76.h */; settings = {ATTRIBUTES = (Public, ); }; };
E9CCF386154172390019878B /* PKWebSocketFrameParser-Hixie76.m in Sources */ = {isa = PBXBuildFile; fileRef = E9CCF384154172390019878B /* PKWebSocketFrameParser-Hixie76.m */; };
E9CCF3A0154199150019878B /* PKWebSocketFrameParser.h in Headers */ = {isa = PBXBuildFile; fileRef = E9CCF39E154199150019878B /* PKWebSocketFrameParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -50,7 +51,6 @@
E9E06688153F6AEF008AC7EF /* PKWebSocketURL.h in Headers */ = {isa = PBXBuildFile; fileRef = E9E06686153F6AEF008AC7EF /* PKWebSocketURL.h */; settings = {ATTRIBUTES = (Public, ); }; };
E9E06689153F6AEF008AC7EF /* PKWebSocketURL.m in Sources */ = {isa = PBXBuildFile; fileRef = E9E06687153F6AEF008AC7EF /* PKWebSocketURL.m */; };
E9E0668C153F7935008AC7EF /* PKWebSocketURLTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E9E0668B153F7935008AC7EF /* PKWebSocketURLTests.m */; };
- E9E066AE15405A49008AC7EF /* PKWebSocketCryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E9E066AD15405A49008AC7EF /* PKWebSocketCryptoTests.m */; };
E9E066BC1540771E008AC7EF /* PKWebSocketConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = E9E066BA1540771E008AC7EF /* PKWebSocketConstants.h */; settings = {ATTRIBUTES = (Public, ); }; };
E9E066BD1540771E008AC7EF /* PKWebSocketConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = E9E066BB1540771E008AC7EF /* PKWebSocketConstants.m */; };
E9F346C1153C40300052DAAE /* AsyncSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = E9F346BF153C40300052DAAE /* AsyncSocket.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -102,6 +102,7 @@
E994C286153C3DF10078AA11 /* PKWebSocketTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PKWebSocketTests-Info.plist"; sourceTree = "<group>"; };
E994C288153C3DF10078AA11 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
E994C28B153C3DF10078AA11 /* PKWebSocketTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PKWebSocketTests.m; sourceTree = "<group>"; };
+ E9B6D9C61544A9B600DF3D4A /* PKWebSocketCryptoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PKWebSocketCryptoTests.m; path = Categories/PKWebSocketCryptoTests.m; sourceTree = "<group>"; };
E9CCF383154172390019878B /* PKWebSocketFrameParser-Hixie76.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "PKWebSocketFrameParser-Hixie76.h"; path = "Frames/PKWebSocketFrameParser-Hixie76.h"; sourceTree = "<group>"; };
E9CCF384154172390019878B /* PKWebSocketFrameParser-Hixie76.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "PKWebSocketFrameParser-Hixie76.m"; path = "Frames/PKWebSocketFrameParser-Hixie76.m"; sourceTree = "<group>"; };
E9CCF39E154199150019878B /* PKWebSocketFrameParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PKWebSocketFrameParser.h; path = Frames/PKWebSocketFrameParser.h; sourceTree = "<group>"; };
@@ -112,7 +113,6 @@
E9E06686153F6AEF008AC7EF /* PKWebSocketURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PKWebSocketURL.h; sourceTree = "<group>"; };
E9E06687153F6AEF008AC7EF /* PKWebSocketURL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PKWebSocketURL.m; sourceTree = "<group>"; };
E9E0668B153F7935008AC7EF /* PKWebSocketURLTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PKWebSocketURLTests.m; sourceTree = "<group>"; };
- E9E066AD15405A49008AC7EF /* PKWebSocketCryptoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PKWebSocketCryptoTests.m; sourceTree = "<group>"; };
E9E066BA1540771E008AC7EF /* PKWebSocketConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PKWebSocketConstants.h; sourceTree = "<group>"; };
E9E066BB1540771E008AC7EF /* PKWebSocketConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PKWebSocketConstants.m; sourceTree = "<group>"; };
E9F346BF153C40300052DAAE /* AsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AsyncSocket.h; path = Submodules/CocoaAsyncSocket/RunLoop/AsyncSocket.h; sourceTree = "<group>"; };
@@ -246,9 +246,9 @@
E994C284153C3DF10078AA11 /* PKWebSocketTests */ = {
isa = PBXGroup;
children = (
+ E9B6D9C91544A9BC00DF3D4A /* Categories */,
E9CCF3A615419A010019878B /* Frames */,
E9008DC5153DD5880038591B /* Handlers */,
- E9E066AD15405A49008AC7EF /* PKWebSocketCryptoTests.m */,
E9E0668B153F7935008AC7EF /* PKWebSocketURLTests.m */,
E9008DBE153DBB170038591B /* PKHTTPRequestTests.m */,
E994C28B153C3DF10078AA11 /* PKWebSocketTests.m */,
@@ -267,6 +267,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
+ E9B6D9C91544A9BC00DF3D4A /* Categories */ = {
+ isa = PBXGroup;
+ children = (
+ E9B6D9C61544A9B600DF3D4A /* PKWebSocketCryptoTests.m */,
+ );
+ name = Categories;
+ sourceTree = "<group>";
+ };
E9CCF381154172020019878B /* Frames */ = {
isa = PBXGroup;
children = (
@@ -456,8 +464,8 @@
E9008E03153E07E80038591B /* PKWebSocketHandler-RFC6455Tests.m in Sources */,
E9E06685153F5E87008AC7EF /* PKWebsocketHandlerTests.m in Sources */,
E9E0668C153F7935008AC7EF /* PKWebSocketURLTests.m in Sources */,
- E9E066AE15405A49008AC7EF /* PKWebSocketCryptoTests.m in Sources */,
E9CCF3A5154199FD0019878B /* PKWebSocketFrameParser-Hixie76Tests.m in Sources */,
+ E9B6D9C71544A9B600DF3D4A /* PKWebSocketCryptoTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
74 PKWebSocketTests/Categories/PKWebSocketCryptoTests.m
@@ -0,0 +1,74 @@
+//
+// 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)testHixie76KeyMustCorretNubmerOfSpaces {
+ 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 is not an integral multiple of spaces");
+}
+
+- (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
+
View
40 PKWebSocketTests/PKWebSocketCryptoTests.m
@@ -1,40 +0,0 @@
-//
-// PKWebSocketCryptoTests.m
-// PKWebSocketCryptoTests
-//
-// Created by Pavel Kunc on 16/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];
-}
-
-
-- (void)testHixie76Key {
- //for (NSUInteger i = 0; i < 100; i++) {
- // pkws_hixie76Key();
- //}
- //STAssertTrue(false,nil);
-}
-
-- (void)testRandomDataReturnsDataOfCorrectLength {
- //NSData *data = [NSData pk_randomBytesOfLength:8];
- //STAssertTrue(false,nil);
-}
-
-@end
-
Please sign in to comment.
Something went wrong with that request. Please try again.