diff --git a/Tests/base/NSStream/ipv6test.m b/Tests/base/NSStream/ipv6test.m deleted file mode 100644 index be6757a410..0000000000 --- a/Tests/base/NSStream/ipv6test.m +++ /dev/null @@ -1,84 +0,0 @@ -#if defined(GNUSTEP_BASE_LIBRARY) -/** - * This test tests IPv6 using NSStream - */ -#import -#import "Testing.h" - -@interface IPV6Server : NSObject - -- (void) main; - -@end - -@implementation IPV6Server - -- (void) main -{ -} - -@end - -int main() -{ - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - - NSInputStream *inputStream; - NSOutputStream *outputStream; - IPV6Server *svr = [[IPV6Server alloc] init]; - - NSString *ipv6ServerAddress = @"::1"; // Replace with your actual IPv6 server address - uint16_t port = 12345; // Replace with the actual port number - - // Resolve the IPv6 address using NSHost - NSHost *host = [NSHost hostWithName: ipv6ServerAddress]; - NSArray *addresses = [host addresses]; - - PASS([addresses count] > 0, "Resolve IPv6 address"); - - NSString *ipv6Address = [addresses objectAtIndex: 0]; - NSThread *thread = [[NSThread alloc] initWithTarget: svr selector: @selector(main) object: nil]; - - PASS(thread != nil, "Created thread for server"); - - [thread start]; - - [NSStream getStreamsToHost: [NSHost hostWithName: ipv6Address] - port: port - inputStream: &inputStream - outputStream: &outputStream]; - - [inputStream open]; - [outputStream open]; - - // Perform your tests here to validate the IPv6 stream - // You can write and read data from the stream and assert the expected results - // For example: - - NSString *testData = @"Test Data"; - NSData *dataToWrite = [testData dataUsingEncoding:NSUTF8StringEncoding]; - NSInteger bytesWritten = [outputStream write: [dataToWrite bytes] maxLength: [dataToWrite length]]; - - PASS(bytesWritten > 0, "Write data to the stream"); - - uint8_t buffer[1024]; - NSInteger bytesRead = [inputStream read:buffer maxLength:1024]; - NSString *receivedString = [[NSString alloc] initWithBytes:buffer length:bytesRead encoding:NSUTF8StringEncoding]; - - PASS(bytesRead > 0, "Read data from the stream"); - PASS([receivedString isEqualToString: testData], "Received data matches the expected data"); - - [inputStream close]; - [outputStream close]; - - [arp release]; - arp = nil; - - return 0; -} -#else -int main() -{ - return 0; -} -#endif 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; +}