diff --git a/Tests/base/NSStream/socket_cs.m b/Tests/base/NSStream/socket_cs.m index f5925f95bb..96e4b585e8 100644 --- a/Tests/base/NSStream/socket_cs.m +++ b/Tests/base/NSStream/socket_cs.m @@ -293,15 +293,15 @@ - (void)stream: (NSStream *)theStream handleEvent: (NSStreamEvent)streamEvent int main() { CREATE_AUTORELEASE_POOL(arp); - NSRunLoop *rl = [NSRunLoop currentRunLoop]; - NSHost *host = [NSHost hostWithAddress: @"127.0.0.1"]; - ServerListener *sli; - ClientListener *cli; - NSString *path = @"socket_cs.m"; - NSString *socketPath = @"test-socket"; - NSDate *end; - - [[NSFileManager defaultManager] removeFileAtPath: socketPath handler: nil]; + NSRunLoop *rl = [NSRunLoop currentRunLoop]; + NSHost *host; + ServerListener *sli; + ClientListener *cli; + NSString *path = @"socket_cs.m"; + NSString *socketPath = @"test-socket"; + NSDate *end; + + host = [NSHost hostWithAddress: @"127.0.0.1"]; NSLog(@"sending and receiving on %@: %@", host, [host address]); goldData = [NSData dataWithContentsOfFile: path]; testData = [NSMutableData dataWithCapacity: 4096]; @@ -309,7 +309,7 @@ int main() { CREATE_AUTORELEASE_POOL(inner); - prefix = @"Test1"; + prefix = @"Test1IPV4"; [testData setLength: 0]; sli = AUTORELEASE([ServerListener new]); cli = AUTORELEASE([ClientListener new]); @@ -351,7 +351,7 @@ int main() { CREATE_AUTORELEASE_POOL(inner); - prefix = @"Test2"; + prefix = @"Test2IPV4"; [testData setLength: 0]; sli = AUTORELEASE([ServerListener new]); cli = AUTORELEASE([ClientListener new]); @@ -360,6 +360,53 @@ int main() [serverStream setDelegate: sli]; [serverStream open]; [serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; + [NSStream getStreamsToHost: host + port: 1234 + inputStream: &clientInput + outputStream: &clientOutput]; + NSLog(@"%@ Client input stream is %@", prefix, clientInput); + NSLog(@"%@ Client output stream is %@", prefix, clientOutput); + [clientInput setDelegate: cli]; + [clientOutput setDelegate: cli]; + [clientInput open]; + [clientOutput open]; + [clientInput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; + [clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; + + end = [NSDate dateWithTimeIntervalSinceNow: 5]; + while (NO == [goldData isEqualToData: testData] + && [end timeIntervalSinceNow] > 0.0) + { + [rl runMode: NSDefaultRunLoopMode beforeDate: end]; + } + PASS([goldData isEqualToData: testData], "Local tcp (blocking open)"); + if ([end timeIntervalSinceNow] < 0.0) + NSLog(@"%@ timed out.\n", prefix); + + [clientInput setDelegate: nil]; + [clientOutput setDelegate: nil]; + DESTROY(serverInput); + DESTROY(serverOutput); + RELEASE(inner); +} + + host = [NSHost hostWithAddress: @"::1"]; + NSLog(@"sending and receiving on %@: %@", host, [host address]); + goldData = [NSData dataWithContentsOfFile: path]; + testData = [NSMutableData dataWithCapacity: 4096]; + +{ + CREATE_AUTORELEASE_POOL(inner); + + prefix = @"Test1IPV6"; + [testData setLength: 0]; + sli = AUTORELEASE([ServerListener new]); + cli = AUTORELEASE([ClientListener new]); + serverStream + = [GSServerStream serverStreamToAddr: [host address] port: 1234]; + [serverStream setDelegate: sli]; + [serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; + [serverStream open]; [NSStream getStreamsToHost: host port: 1234 inputStream: &clientInput @@ -368,6 +415,48 @@ int main() NSLog(@"%@ Client output stream is %p", prefix, clientOutput); [clientInput setDelegate: cli]; [clientOutput setDelegate: cli]; + [clientInput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; + [clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; + [clientInput open]; + [clientOutput open]; + + end = [NSDate dateWithTimeIntervalSinceNow: 5]; + while (NO == [goldData isEqualToData: testData] + && [end timeIntervalSinceNow] > 0.0) + { + [rl runMode: NSDefaultRunLoopMode beforeDate: end]; + } + PASS([goldData isEqualToData: testData], "Local tcp"); + if ([end timeIntervalSinceNow] < 0.0) + NSLog(@"%@ timed out.\n", prefix); + + [clientInput setDelegate: nil]; + [clientOutput setDelegate: nil]; + DESTROY(serverInput); + DESTROY(serverOutput); + RELEASE(inner); +} + +{ + CREATE_AUTORELEASE_POOL(inner); + + prefix = @"Test2IPV6"; + [testData setLength: 0]; + sli = AUTORELEASE([ServerListener new]); + cli = AUTORELEASE([ClientListener new]); + serverStream + = [GSServerStream serverStreamToAddr: [host address] port: 1234]; + [serverStream setDelegate: sli]; + [serverStream open]; + [serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; + [NSStream getStreamsToHost: host + port: 1234 + inputStream: &clientInput + outputStream: &clientOutput]; + NSLog(@"%@ Client input stream is %@", prefix, clientInput); + NSLog(@"%@ Client output stream is %@", prefix, clientOutput); + [clientInput setDelegate: cli]; + [clientOutput setDelegate: cli]; [clientInput open]; [clientOutput open]; [clientInput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode]; @@ -390,6 +479,11 @@ int main() RELEASE(inner); } + [[NSFileManager defaultManager] removeFileAtPath: socketPath handler: nil]; + NSLog(@"sending and receiving on %@", socketPath); + goldData = [NSData dataWithContentsOfFile: path]; + testData = [NSMutableData dataWithCapacity: 4096]; + { CREATE_AUTORELEASE_POOL(inner); diff --git a/Tests/base/NSURLConnection/test08.m b/Tests/base/NSURLConnection/test08.m new file mode 100644 index 0000000000..395123e02f --- /dev/null +++ b/Tests/base/NSURLConnection/test08.m @@ -0,0 +1,119 @@ +/** + * Tests for HTTPS without authorization (big request) + */ +#import +#import "Helpers/NSURLConnectionTest.h" +#import "Helpers/TestWebServer.h" +#import + +int main(int argc, char **argv, char **env) +{ + CREATE_AUTORELEASE_POOL(arp); + NSFileManager *fm; + NSBundle *bundle; + BOOL loaded; + NSString *helperPath; + + /* The following test cases depend on the GSInetServerStream + * class which is completely broken on Windows. + * + * See: https://github.com/gnustep/libs-base/issues/266 + * + * We will mark the test cases as hopeful on Windows. + */ + //#if defined(_WIN32) + // NSLog(@"Marking local web server tests as hopeful because GSInetServerStream is broken on Windows"); + // testHopeful = YES; + //#endif + + // load the test suite's classes + fm = [NSFileManager defaultManager]; + helperPath = [[fm currentDirectoryPath] + stringByAppendingString: @"/Helpers/TestConnection.bundle"]; + bundle = [NSBundle bundleWithPath: helperPath]; + loaded = [bundle load]; + + if (loaded) + { + NSDictionary *d; + Class testClass; + NSDictionary *refs; + TestWebServer *server; + NSMutableString *payload; + NSURLConnectionTest *testCase; + BOOL debug = NO; + int i; + + testClass = [bundle principalClass]; // NSURLConnectionTest + + // the extra dictionary commanding to use HTTPS + d = [NSDictionary dictionaryWithObjectsAndKeys: + @"HTTPS", @"Protocol", + nil]; + // create a shared TestWebServer instance for performance + server = [[[testClass testWebServerClass] alloc] + initWithAddress: @"ip6-localhost" + port: @"1234" + mode: NO + extra: d]; + [server setDebug: debug]; + [server start: d]; // localhost:1234 HTTPS + + /* Simple POST via HTTPS with the response's status code 400 and + * non-empty response's body + */ + testCase = [testClass new]; + [testCase setDebug: debug]; + /* the reference set difference (from the default reference set) + * we expect the flags must not be set because we request a path + * with no authorization. See NSURLConnectionTest.h for details + * (the key words are 'TestCase' and 'ReferenceFlags') + */ + refs = [NSDictionary dictionaryWithObjectsAndKeys: + @"NO", @"GOTUNAUTHORIZED", + @"NO", @"AUTHORIZED", + @"NO", @"NOTAUTHORIZED", + nil]; + + // the extra dictionary with test case's parameters + payload = [NSMutableString stringWithCapacity: 1024 * 128]; + for (i = 0; i < 2000; i++) + { + [payload appendFormat: + @"%09daaaaaaaaaabbbbbbbbbbcccccccccccdddddddddd\n", + i * 50]; + } + d = [NSDictionary dictionaryWithObjectsAndKeys: + server, @"Instance", // we use the shared TestWebServer instance + @"400/withoutauth", @"Path", // request the handler responding with 400 + @"400", @"StatusCode", // the expected status code + @"You have issued a request with invalid data", @"Content", // expected + payload, @"Payload", // the custom payload + @"POST", @"Method", // use POST + refs, @"ReferenceFlags", // the expected reference set difference + nil]; + [testCase setUpTest: d]; + [testCase startTest: d]; + PASS([testCase isSuccess], "HTTPS... big payload... response 400 .... POST https://ip6-localhost:1234/400/withoutauth"); + [testCase tearDownTest: d]; + DESTROY(testCase); + + // cleaning + [server stop]; + DESTROY(server); + } + else + { + // no classes no tests + [NSException raise: NSInternalInconsistencyException + format: @"can't load bundle TestConnection"]; + } + + //#if defined(_WIN32) + // testHopeful = NO; + //#endif + + DESTROY(arp); + + return 0; +}