use safer port numbers

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39461 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2016-03-05 16:13:44 +00:00
parent 86e8a7b27d
commit 6468dcfd1a
15 changed files with 141 additions and 138 deletions

View file

@ -58,7 +58,7 @@
isSecure = [[defs stringForKey: @"Secure"] boolValue]; isSecure = [[defs stringForKey: @"Secure"] boolValue];
if (port == 0) port = 54321; if (port == 0) port = 1234;
file = [defs stringForKey: @"FileName"]; file = [defs stringForKey: @"FileName"];
RETAIN(file); RETAIN(file);

View file

@ -40,7 +40,7 @@
NSString *file; NSString *file;
int port = [[defs stringForKey: @"Port"] intValue]; int port = [[defs stringForKey: @"Port"] intValue];
if (port == 0) port = 54321; if (port == 0) port = 1234;
count = [[defs stringForKey: @"Count"] intValue]; count = [[defs stringForKey: @"Count"] intValue];
if (count <= 0) count = 1; if (count <= 0) count = 1;

View file

@ -30,7 +30,7 @@ int main()
arguments: [NSArray arrayWithObjects: arguments: [NSArray arrayWithObjects:
@"-FileName", @"Chunked.dat", @"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file @"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"54321", @"-Port", @"1234",
@"-Count", @"1", @"-Count", @"1",
nil]]; nil]];
if (t != nil) if (t != nil)
@ -43,7 +43,7 @@ int main()
// Pause to allow server subtask to set up. // Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]]; [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
u = [NSURL URLWithString: @"http://localhost:54321/chunked"]; u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
// Talk to server. // Talk to server.
data = [u resourceDataUsingCache: NO]; data = [u resourceDataUsingCache: NO];
// Get status code // Get status code
@ -58,7 +58,7 @@ int main()
arguments: [NSArray arrayWithObjects: arguments: [NSArray arrayWithObjects:
@"-FileName", @"Chunked.dat", @"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file @"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"54321", @"-Port", @"1234",
@"-Count", @"1", @"-Count", @"1",
nil]]; nil]];
if (t != nil) if (t != nil)
@ -74,7 +74,7 @@ int main()
// Pause to allow server subtask to set up. // Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]]; [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
u = [NSURL URLWithString: @"http://localhost:54321/chunked"]; u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
request = [NSURLRequest requestWithURL: u]; request = [NSURLRequest requestWithURL: u];
response = nil; response = nil;
@ -91,7 +91,7 @@ int main()
[t waitUntilExit]; [t waitUntilExit];
} }
url = [NSURL URLWithString: @"http://localhost:54321/"]; url = [NSURL URLWithString: @"http://localhost:1234/"];
/* Ask the 'respond' helper to send back a response containing /* Ask the 'respond' helper to send back a response containing
* 'hello' and to shrink the write buffer size it uses on each * 'hello' and to shrink the write buffer size it uses on each
@ -134,7 +134,7 @@ int main()
* that loads work when handles are flushed from the cache. * that loads work when handles are flushed from the cache.
*/ */
u = [NSURL URLWithString: [NSString stringWithFormat: u = [NSURL URLWithString: [NSString stringWithFormat:
@"http://localhost:54321/%d", i % 18]]; @"http://localhost:1234/%d", i % 18]];
// Talk to server. // Talk to server.
data = [u resourceDataUsingCache: NO]; data = [u resourceDataUsingCache: NO];
// Get status code // Get status code

View file

@ -44,7 +44,7 @@ int main()
// remove the captured data from a possible previous run // remove the captured data from a possible previous run
[fm removeItemAtPath: file error: NULL]; [fm removeItemAtPath: file error: NULL];
// making a POST request // making a POST request
url = [NSURL URLWithString: @"http://localhost:54321/"]; url = [NSURL URLWithString: @"http://localhost:1234/"];
request = [NSMutableURLRequest requestWithURL: url]; request = [NSMutableURLRequest requestWithURL: url];
data = [m dataUsingEncoding: NSUTF8StringEncoding]; data = [m dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data]; [request setHTTPBody: data];
@ -86,7 +86,7 @@ int main()
// remove the captured data from a possible previous run // remove the captured data from a possible previous run
[fm removeItemAtPath: file error: NULL]; [fm removeItemAtPath: file error: NULL];
// making a POST request // making a POST request
url = [NSURL URLWithString: @"https://localhost:54321/"]; url = [NSURL URLWithString: @"https://localhost:1234/"];
request = [NSMutableURLRequest requestWithURL: url]; request = [NSMutableURLRequest requestWithURL: url];
data = [m dataUsingEncoding: NSUTF8StringEncoding]; data = [m dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data]; [request setHTTPBody: data];

View file

@ -13,7 +13,7 @@
* test. * test.
* *
* The test case which the NSURLConnectionTest implements by default is connecting * The test case which the NSURLConnectionTest implements by default is connecting
* to the http://localhost:54321/ whith the HTTP method 'GET'. You can change variable * to the http://127.0.0.1:1234/ whith the HTTP method 'GET'. You can change variable
* parts of process by supplying a custom dictionary to the method -[setUpTest:] * parts of process by supplying a custom dictionary to the method -[setUpTest:]
* before the test case is started by a call of the -[startTest:]. The use pattern: * before the test case is started by a call of the -[startTest:]. The use pattern:
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
@ -57,12 +57,12 @@
* (the instance will be run within a detached thread). * (the instance will be run within a detached thread).
* Default: NO * Default: NO
* 'Address' - the address of the remote side. * 'Address' - the address of the remote side.
* Default: localhost * Default: 127.0.0.1
* 'Port' - the port of the remote side. * 'Port' - the port of the remote side.
* Default: 54321 * Default: 1234
* 'AuxPort' - the port of the auxilliary remote side (where the connection * 'AuxPort' - the port of the auxilliary remote side (where the connection
* to be redirected). * to be redirected).
* Default: 54322 * Default: 1235
* 'Protocol' - the network protocol (supports currently http, https). * 'Protocol' - the network protocol (supports currently http, https).
* Default: http * Default: http
* 'Path' - the path of the URL. * 'Path' - the path of the URL.

View file

@ -583,15 +583,15 @@ didReceiveResponse:(NSURLResponse *)response
} }
if (nil == address) if (nil == address)
{ {
address = @"localhost"; address = @"127.0.0.1";
} }
if (nil == port) if (nil == port)
{ {
port = @"54321"; port = @"1234";
} }
if (nil == auxPort) if (nil == auxPort)
{ {
auxPort = @"54322"; auxPort = @"1235";
} }
if (nil == path) if (nil == path)
{ {

View file

@ -13,7 +13,7 @@
* It is designed to call the delegate's callbacks (if implemented) of * It is designed to call the delegate's callbacks (if implemented) of
* the TestWebServerDelegate protocol for every request made to * the TestWebServerDelegate protocol for every request made to
* the SimpleWebServer's assigned address on the SimpleWebServer's assigned port * the SimpleWebServer's assigned address on the SimpleWebServer's assigned port
* (by default 127.0.0.1 and 54321 respectively). However it currently doesn't * (by default 127.0.0.1 and 1234 respectively). However it currently doesn't
* handle any request on it's own. Instead the class uses a collection of * handle any request on it's own. Instead the class uses a collection of
* handlers. Every handler makes a custom response. So the TestWebServer only * handlers. Every handler makes a custom response. So the TestWebServer only
* has to dispatch a request to a corresponding handler and then to send back * has to dispatch a request to a corresponding handler and then to send back
@ -30,7 +30,7 @@
* @"https", @"Protocol", * @"https", @"Protocol",
* nil]; * nil];
* TestWebServer *server = [[TestWebServer alloc] initWithAddress: @"127.0.0.1" * TestWebServer *server = [[TestWebServer alloc] initWithAddress: @"127.0.0.1"
* port: @"54321" * port: @"1234"
* mode: NO * mode: NO
* extra: extra]; * extra: extra];
* ADelegateClass *del = [ADelegateClass new]; * ADelegateClass *del = [ADelegateClass new];
@ -72,7 +72,7 @@
* 301 "Redirect to <URL>" * 301 "Redirect to <URL>"
* Returns in the header 'Location' a new <URL> which by default * Returns in the header 'Location' a new <URL> which by default
* has the same protocol, address but the port is incremented by * has the same protocol, address but the port is incremented by
* 1 (e.g. http://localhost:54322/ with other parameters set to * 1 (e.g. http://127.0.0.1:1235/ with other parameters set to
* their default values). * their default values).
* 400 "You have issued a request with invalid data" * 400 "You have issued a request with invalid data"
* 401 "Invalid login or password" * 401 "Invalid login or password"

View file

@ -27,7 +27,7 @@
/* default 'constants' */ /* default 'constants' */
#define DEFAULTADDRESS @"127.0.0.1" #define DEFAULTADDRESS @"127.0.0.1"
#define DEFAULTPORT @"54321" #define DEFAULTPORT @"1234"
#define DEFAULTMODE NO #define DEFAULTMODE NO
#define DEFAULTLOGIN @"login" #define DEFAULTLOGIN @"login"
#define DEFAULTPASSWORD @"password" #define DEFAULTPASSWORD @"password"
@ -58,7 +58,7 @@
mode:(BOOL)detached mode:(BOOL)detached
extra:(id)extra extra:(id)extra
{ {
if((self = [super init]) != nil) if ((self = [super init]) != nil)
{ {
_debug = NO; _debug = NO;
_address = [[NSHost hostWithName: address] address]; _address = [[NSHost hostWithName: address] address];
@ -69,31 +69,31 @@
_login = nil; _login = nil;
_isSecure = NO; _isSecure = NO;
if([extra isKindOfClass: [NSDictionary class]]) if ([extra isKindOfClass: [NSDictionary class]])
{ {
NSDictionary *d = extra; NSDictionary *d = extra;
NSString *proto; NSString *proto;
if((_password = [d objectForKey: @"Password"]) != nil) if ((_password = [d objectForKey: @"Password"]) != nil)
{ {
RETAIN(_password); RETAIN(_password);
} }
if((_login = [d objectForKey: @"Login"]) != nil) if ((_login = [d objectForKey: @"Login"]) != nil)
{ {
RETAIN(_login); RETAIN(_login);
} }
if((proto = [d objectForKey: @"Protocol"]) != nil && if ((proto = [d objectForKey: @"Protocol"]) != nil &&
[[proto lowercaseString] isEqualToString: @"https"]) [[proto lowercaseString] isEqualToString: @"https"])
{ {
_isSecure = YES; _isSecure = YES;
} }
} }
if(nil == _login) if (nil == _login)
{ {
_login = DEFAULTLOGIN; RETAIN(_login); _login = DEFAULTLOGIN; RETAIN(_login);
} }
if(nil == _password) if (nil == _password)
{ {
_password = DEFAULTPASSWORD; RETAIN(_password); _password = DEFAULTPASSWORD; RETAIN(_password);
} }
@ -117,7 +117,7 @@
_lock = [[NSConditionLock alloc] initWithCondition: READY]; _lock = [[NSConditionLock alloc] initWithCondition: READY];
_threadToQuit = NO; _threadToQuit = NO;
if(detached) if (detached)
{ {
_serverThread = [[NSThread alloc] initWithTarget: self _serverThread = [[NSThread alloc] initWithTarget: self
selector: @selector(_startDetached:) selector: @selector(_startDetached:)
@ -147,18 +147,18 @@
- (void)start:(id)extra - (void)start:(id)extra
{ {
if([_server port] != nil) if ([_server port] != nil)
{ {
if(YES == _debug) if (YES == _debug)
{ {
NSWarnMLog(@"SimpleWebServer already started"); NSWarnMLog(@"SimpleWebServer already started");
} }
return; return;
} }
if(nil != _serverThread) if (nil != _serverThread)
{ {
if(![_serverThread isExecuting]) if (![_serverThread isExecuting])
{ {
NSTimeInterval duration = 0.0; NSTimeInterval duration = 0.0;
[_serverThread start]; [_serverThread start];
@ -172,7 +172,7 @@
duration += TIMING; duration += TIMING;
} }
[_lock unlock]; [_lock unlock];
if(duration >= MAXDURATION && if (duration >= MAXDURATION &&
nil != _delegate && nil != _delegate &&
[_delegate respondsToSelector: @selector(timeoutExceededByHandler:)]) [_delegate respondsToSelector: @selector(timeoutExceededByHandler:)])
{ {
@ -193,17 +193,17 @@
- (void)stop - (void)stop
{ {
if([_server port] == nil) if ([_server port] == nil)
{ {
if(YES == _debug) if (YES == _debug)
{ {
NSWarnMLog(@"SimpleWebServer already stopped"); NSWarnMLog(@"SimpleWebServer already stopped");
} }
return; return;
} }
if(nil != _serverThread) if (nil != _serverThread)
{ {
if([_serverThread isExecuting]) if ([_serverThread isExecuting])
{ {
NSTimeInterval duration = 0.0; NSTimeInterval duration = 0.0;
_threadToQuit = YES; // this makes the detached thread quiting from it's runloop _threadToQuit = YES; // this makes the detached thread quiting from it's runloop
@ -217,7 +217,7 @@
duration += TIMING; duration += TIMING;
} }
[_lock unlockWithCondition: READY]; [_lock unlockWithCondition: READY];
if(duration >= MAXDURATION && if (duration >= MAXDURATION &&
nil != _delegate && nil != _delegate &&
[_delegate respondsToSelector: @selector(timeoutExceededByHandler:)]) [_delegate respondsToSelector: @selector(timeoutExceededByHandler:)])
{ {
@ -248,21 +248,21 @@
en = [[path pathComponents] objectEnumerator]; en = [[path pathComponents] objectEnumerator];
while((component = [en nextObject]) != nil) while((component = [en nextObject]) != nil)
{ {
if((handler = [_traversalMap objectForKey: component]) != nil) if ((handler = [_traversalMap objectForKey: component]) != nil)
{ {
// the handler has been found // the handler has been found
break; // while break; // while
} }
} }
if(nil == component) if (nil == component)
{ {
// no component found... default 204 // no component found... default 204
component = @"204"; component = @"204";
handler = [_traversalMap objectForKey: component]; handler = [_traversalMap objectForKey: component];
} }
if(handler == [handler class]) if (handler == [handler class])
{ {
// it is a Class not an instance... instantiate and substitute // it is a Class not an instance... instantiate and substitute
// instead of the Class // instead of the Class
@ -275,9 +275,9 @@
[handler setDelegate: _delegate]; [handler setDelegate: _delegate];
[handler setLogin: _login]; [handler setLogin: _login];
[handler setPassword: _password]; [handler setPassword: _password];
if([handler respondsToSelector: @selector(setURLString:)]) if ([handler respondsToSelector: @selector(setURLString:)])
{ {
if([handler isKindOfClass: [HandlerIndex class]]) if ([handler isKindOfClass: [HandlerIndex class]])
{ {
NSString *urlString = [NSString stringWithFormat: @"%@://%@:%@/", NSString *urlString = [NSString stringWithFormat: @"%@://%@:%@/",
_isSecure ? @"https" : @"http", _isSecure ? @"https" : @"http",
@ -286,9 +286,9 @@
[(HandlerIndex *)handler setURLString: urlString]; [(HandlerIndex *)handler setURLString: urlString];
} }
else if([handler isKindOfClass: [Handler301 class]]) else if ([handler isKindOfClass: [Handler301 class]])
{ {
// by default http://localhost:54322/ // by default http://127.0.0.1:1235/
NSString *port = [NSString stringWithFormat: @"%u", [_port intValue] + 1]; // the TestWebServer's port + 1 NSString *port = [NSString stringWithFormat: @"%u", [_port intValue] + 1]; // the TestWebServer's port + 1
NSString *urlString = [NSString stringWithFormat: @"%@://%@:%@/", NSString *urlString = [NSString stringWithFormat: @"%@://%@:%@/",
_isSecure ? @"https" : @"http", _isSecure ? @"https" : @"http",
@ -379,9 +379,9 @@
_server = [SimpleWebServer new]; _server = [SimpleWebServer new];
[_server setDebug: _debug]; [_server setDebug: _debug];
[_server setDelegate: self]; [_server setDelegate: self];
if(_isSecure) if (_isSecure)
{ {
if([_address isEqualToString: @"127.0.0.1"] || if ([_address isEqualToString: @"127.0.0.1"] ||
[_address isEqualToString: @"localhost"]) [_address isEqualToString: @"localhost"])
{ {
certPath = [[NSBundle bundleForClass: [self class]] certPath = [[NSBundle bundleForClass: [self class]]
@ -403,7 +403,7 @@
} }
status = [_server setAddress: _address port: _port secure: secure]; // run the server status = [_server setAddress: _address port: _port secure: secure]; // run the server
if(!status) if (!status)
{ {
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
format: @"The server hasn't run. Perhaps the port %@ is invalid", DEFAULTPORT]; format: @"The server hasn't run. Perhaps the port %@ is invalid", DEFAULTPORT];
@ -412,10 +412,10 @@
- (void)_stopHTTPServer - (void)_stopHTTPServer
{ {
if(nil != _server && [_server port] != nil) if (nil != _server && [_server port] != nil)
{ {
[_server stop]; // shut down the server [_server stop]; // shut down the server
if(YES == _debug) if (YES == _debug)
{ {
NSLog(@"%@: stopped SimpleWebServer %@", self, _server); NSLog(@"%@: stopped SimpleWebServer %@", self, _server);
} }
@ -432,7 +432,7 @@
[self _startHTTPServer: extra]; [self _startHTTPServer: extra];
[_lock unlockWithCondition: STARTED]; [_lock unlockWithCondition: STARTED];
if(YES == _debug) if (YES == _debug)
{ {
NSLog(@"%@: enter into runloop in detached thread %@", self, [NSThread currentThread]); NSLog(@"%@: enter into runloop in detached thread %@", self, [NSThread currentThread]);
} }
@ -444,12 +444,12 @@
duration += TIMING; duration += TIMING;
} }
if(YES == _debug) if (YES == _debug)
{ {
NSLog(@"%@: exit from runloop in detached thread %@", self, [NSThread currentThread]); NSLog(@"%@: exit from runloop in detached thread %@", self, [NSThread currentThread]);
} }
if(duration >= MAXDURATION && if (duration >= MAXDURATION &&
nil != _delegate && nil != _delegate &&
[_delegate respondsToSelector: @selector(timeoutExceededByHandler:)]) [_delegate respondsToSelector: @selector(timeoutExceededByHandler:)])
{ {

View file

@ -3,25 +3,25 @@
* Author: Sergei Golovin <Golovin.SV@gmail.com> * Author: Sergei Golovin <Golovin.SV@gmail.com>
* *
* Runs two TestWebServer instances to check how the class TestWebServer * Runs two TestWebServer instances to check how the class TestWebServer
* behaves. Visit http://localhost:54321/index to see all supported resources. * behaves. Visit http://127.0.0.1:1234/index to see all supported resources.
* *
* If you visit the main TestWebServer instance with the following command: * If you visit the main TestWebServer instance with the following command:
* *
* wget -O - --user=login --password=password http://localhost:54321/301 2>&1 * wget -O - --user=login --password=password http://127.0.0.1:1234/301 2>&1
* *
* you should get a session log like this: * you should get a session log like this:
* *
* --2014-08-13 12:08:01-- http://localhost:54321/301 * --2014-08-13 12:08:01-- http://127.0.0.1:1234/301
* Resolving localhost (localhost)... 127.0.0.1 * Resolving 127.0.0.1 (localhost)... 127.0.0.1
* Connecting to localhost (localhost)|127.0.0.1|:54321... connected. * Connecting to 127.0.0.1 (localhost)|127.0.0.1|:1234... connected.
* HTTP request sent, awaiting response... 401 Unauthorized * HTTP request sent, awaiting response... 401 Unauthorized
* Reusing existing connection to localhost:54321. * Reusing existing connection to 127.0.0.1:1234.
* HTTP request sent, awaiting response... 301 Moved Permanently * HTTP request sent, awaiting response... 301 Moved Permanently
* Location: http://127.0.0.1:54322/ [following] * Location: http://127.0.0.1:1235/ [following]
* --2014-08-13 12:08:01-- http://127.0.0.1:54322/ * --2014-08-13 12:08:01-- http://127.0.0.1:1235/
* Connecting to 127.0.0.1:54322... connected. * Connecting to 127.0.0.1:1235... connected.
* HTTP request sent, awaiting response... 401 Unauthorized * HTTP request sent, awaiting response... 401 Unauthorized
* Reusing existing connection to 127.0.0.1:54322. * Reusing existing connection to 127.0.0.1:1235.
* HTTP request sent, awaiting response... 204 No Content * HTTP request sent, awaiting response... 204 No Content
* Length: 0 * Length: 0
* Saving to: STDOUT * Saving to: STDOUT
@ -47,11 +47,11 @@ int main(int argc, char **argv, char **env)
fm = [NSFileManager defaultManager]; fm = [NSFileManager defaultManager];
helperPath = [[fm currentDirectoryPath] helperPath = [[fm currentDirectoryPath]
stringByAppendingString: @"/TestConnection.bundle"]; stringByAppendingString: @"/TestConnection.bundle"];
bundle = [NSBundle bundleWithPath: helperPath]; bundle = [NSBundle bundleWithPath: helperPath];
loaded = [bundle load]; loaded = [bundle load];
if(loaded) if (loaded)
{ {
TestWebServer *server1; TestWebServer *server1;
TestWebServer *server2; TestWebServer *server2;
@ -61,23 +61,25 @@ int main(int argc, char **argv, char **env)
testClass = [bundle principalClass]; // NSURLConnectionTest testClass = [bundle principalClass]; // NSURLConnectionTest
d = [NSDictionary dictionaryWithObjectsAndKeys: d = [NSDictionary dictionaryWithObjectsAndKeys:
// @"https", @"Protocol", // @"https", @"Protocol",
nil]; nil];
server1 = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost" server1 = [[[testClass testWebServerClass] alloc]
port: @"54321" initWithAddress: @"127.0.0.1"
mode: NO port: @"1234"
extra: d]; mode: NO
extra: d];
[server1 setDebug: debug]; [server1 setDebug: debug];
[server1 start: d]; // 127.0.0.1:54321 HTTP [server1 start: d]; // 127.0.0.1:1234 HTTP
server2 = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost" server2 = [[[testClass testWebServerClass] alloc]
port: @"54322" initWithAddress: @"127.0.0.1"
mode: NO port: @"1235"
extra: d]; mode: NO
extra: d];
[server2 setDebug: debug]; [server2 setDebug: debug];
[server2 start: d]; // 127.0.0.1:54322 HTTP [server2 start: d]; // 127.0.0.1:1235 HTTP
while(YES) while (YES)
{ {
[[NSRunLoop currentRunLoop] [[NSRunLoop currentRunLoop]
runUntilDate: [NSDate dateWithTimeIntervalSinceNow: TIMING]]; runUntilDate: [NSDate dateWithTimeIntervalSinceNow: TIMING]];

View file

@ -35,7 +35,7 @@ int main(int argc, char **argv, char **env)
// create a shared TestWebServer instance for performance // create a shared TestWebServer instance for performance
server = [[testClass testWebServerClass] new]; server = [[testClass testWebServerClass] new];
[server setDebug: debug]; [server setDebug: debug];
[server start: nil]; // 127.0.0.1:54321 HTTP [server start: nil]; // 127.0.0.1:1234 HTTP
/* /*
* Simple GET via HTTP with empty response's body and * Simple GET via HTTP with empty response's body and
@ -49,7 +49,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "GET http://localhost:54321"); PASS([testCase isSuccess], "GET http://localhost:1234/");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -68,7 +68,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "response 400 .... GET http://localhost:54321/400"); PASS([testCase isSuccess], "response 400 .... GET http://localhost:1234/400");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -89,7 +89,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "payload... response 400 .... POST http://localhost:54321/400"); PASS([testCase isSuccess], "payload... response 400 .... POST http://localhost:1234/400");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -115,7 +115,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "redirecting... GET http://localhost:54321/301"); PASS([testCase isSuccess], "redirecting... GET http://localhost:1234/301");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);

View file

@ -19,11 +19,11 @@ int main(int argc, char **argv, char **env)
// load the test suite's classes // load the test suite's classes
fm = [NSFileManager defaultManager]; fm = [NSFileManager defaultManager];
helperPath = [[fm currentDirectoryPath] helperPath = [[fm currentDirectoryPath]
stringByAppendingString: @"/Helpers/TestConnection.bundle"]; stringByAppendingString: @"/Helpers/TestConnection.bundle"];
bundle = [NSBundle bundleWithPath: helperPath]; bundle = [NSBundle bundleWithPath: helperPath];
loaded = [bundle load]; loaded = [bundle load];
if(loaded) if (loaded)
{ {
NSDictionary *d; NSDictionary *d;
Class testClass; Class testClass;
@ -36,15 +36,16 @@ int main(int argc, char **argv, char **env)
// the extra dictionary commanding to use HTTPS // the extra dictionary commanding to use HTTPS
d = [NSDictionary dictionaryWithObjectsAndKeys: d = [NSDictionary dictionaryWithObjectsAndKeys:
@"HTTPS", @"Protocol", @"HTTPS", @"Protocol",
nil]; nil];
// create a shared TestWebServer instance for performance // create a shared TestWebServer instance for performance
server = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost" server = [[[testClass testWebServerClass] alloc]
port: @"54321" initWithAddress: @"127.0.0.1"
mode: NO port: @"1234"
extra: d]; mode: NO
extra: d];
[server setDebug: debug]; [server setDebug: debug];
[server start: d]; // 127.0.0.1:54321 HTTPS [server start: d]; // 127.0.0.1:1234 HTTPS
/* /*
* Simple GET via HTTPS with empty response's body and * Simple GET via HTTPS with empty response's body and
@ -54,11 +55,11 @@ int main(int argc, char **argv, char **env)
[testCase setDebug: debug]; [testCase setDebug: debug];
// the extra dictionary with test case's parameters // the extra dictionary with test case's parameters
d = [NSDictionary dictionaryWithObjectsAndKeys: d = [NSDictionary dictionaryWithObjectsAndKeys:
server, @"Instance", // we use the shared TestWebServer instance server, @"Instance", // we use the shared TestWebServer instance
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... GET https://localhost:54321"); PASS([testCase isSuccess], "HTTPS... GET https://127.0.0.1:1234/");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -70,14 +71,14 @@ int main(int argc, char **argv, char **env)
[testCase setDebug: debug]; [testCase setDebug: debug];
// the extra dictionary with test case's parameters // the extra dictionary with test case's parameters
d = [NSDictionary dictionaryWithObjectsAndKeys: d = [NSDictionary dictionaryWithObjectsAndKeys:
server, @"Instance", // we use the shared TestWebServer instance server, @"Instance", // we use the shared TestWebServer instance
@"400", @"Path", // request the handler responding with 400 @"400", @"Path", // request the handler responding with 400
@"400", @"StatusCode", // the expected status code @"400", @"StatusCode", // the expected status code
@"You have issued a request with invalid data", @"Content", // the expected response's body @"You have issued a request with invalid data", @"Content",
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... response 400 .... GET https://localhost:54321/400"); PASS([testCase isSuccess], "HTTPS... response 400 .... GET https://localhost:1234/400");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -89,16 +90,16 @@ int main(int argc, char **argv, char **env)
[testCase setDebug: debug]; [testCase setDebug: debug];
// the extra dictionary with test case's parameters // the extra dictionary with test case's parameters
d = [NSDictionary dictionaryWithObjectsAndKeys: d = [NSDictionary dictionaryWithObjectsAndKeys:
server, @"Instance", // we use the shared TestWebServer instance server, @"Instance", // we use the shared TestWebServer instance
@"400", @"Path", // request the handler responding with 400 @"400", @"Path", // request the handler responding with 400
@"400", @"StatusCode", // the expected status code @"400", @"StatusCode", // the expected status code
@"You have issued a request with invalid data", @"Content", // the expected response's body @"You have issued a request with invalid data", @"Content",
@"Some payload", @"Payload", // the custom payload @"Some payload", @"Payload", // the custom payload
@"POST", @"Method", // use POST @"POST", @"Method", // use POST
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... payload... response 400 .... POST https://localhost:54321/400"); PASS([testCase isSuccess], "HTTPS... payload... response 400 .... POST https://localhost:1234/400");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -112,19 +113,19 @@ int main(int argc, char **argv, char **env)
[testCase setDebug: debug]; [testCase setDebug: debug];
// the reference set difference (from the default reference set) we expect // the reference set difference (from the default reference set) we expect
refs = [NSDictionary dictionaryWithObjectsAndKeys: refs = [NSDictionary dictionaryWithObjectsAndKeys:
@"YES", @"GOTREDIRECT", @"YES", @"GOTREDIRECT",
nil]; nil];
// the extra dictionary with test case's parameters // the extra dictionary with test case's parameters
d = [NSDictionary dictionaryWithObjectsAndKeys: d = [NSDictionary dictionaryWithObjectsAndKeys:
server, @"Instance", // we use the shared TestWebServer instance server, @"Instance", // we use the shared TestWebServer instance
@"/301", @"Path", // request the handler responding with a redirect @"/301", @"Path", // request the handler responding with a redirect
@"/", @"RedirectPath", // the URL's path of redirecting @"/", @"RedirectPath", // the URL's path of redirecting
@"YES", @"IsAuxilliary", // start an auxilliary TestWebServer instance @"YES", @"IsAuxilliary", // start an auxilliary TestWebServer instance
refs, @"ReferenceFlags", // the expected reference set difference refs, @"ReferenceFlags", // the expected reference set difference
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... redirecting... GET https://localhost:54321/301"); PASS([testCase isSuccess], "HTTPS... redirecting... GET https://localhost:1234/301");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -136,7 +137,7 @@ int main(int argc, char **argv, char **env)
{ {
// no classes no tests // no classes no tests
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
format: @"can't load bundle TestConnection"]; format: @"can't load bundle TestConnection"];
} }
DESTROY(arp); DESTROY(arp);

View file

@ -35,7 +35,7 @@ int main(int argc, char **argv, char **env)
// create a shared TestWebServer instance for performance // create a shared TestWebServer instance for performance
server = [[testClass testWebServerClass] new]; server = [[testClass testWebServerClass] new];
[server setDebug: debug]; [server setDebug: debug];
[server start: nil]; // 127.0.0.1:54321 HTTP [server start: nil]; // 127.0.0.1:1234 HTTP
/* /*
* Simple GET via HTTP without authorization with empty response's body and * Simple GET via HTTP without authorization with empty response's body and
@ -59,7 +59,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "no auth... GET http://localhost:54321/withoutauth"); PASS([testCase isSuccess], "no auth... GET http://localhost:1234/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -87,7 +87,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "no auth... response 400 .... GET http://localhost:54321/400/withoutauth"); PASS([testCase isSuccess], "no auth... response 400 .... GET http://localhost:1234/400/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -117,7 +117,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "no auth... payload... response 400 .... POST http://localhost:54321/400/withoutauth"); PASS([testCase isSuccess], "no auth... payload... response 400 .... POST http://localhost:1234/400/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -148,7 +148,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "no auth... redirecting... GET http://localhost:54321/301/withoutauth"); PASS([testCase isSuccess], "no auth... redirecting... GET http://localhost:1234/301/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);

View file

@ -39,11 +39,11 @@ int main(int argc, char **argv, char **env)
nil]; nil];
// create a shared TestWebServer instance for performance // create a shared TestWebServer instance for performance
server = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost" server = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost"
port: @"54321" port: @"1234"
mode: NO mode: NO
extra: d]; extra: d];
[server setDebug: debug]; [server setDebug: debug];
[server start: d]; // 127.0.0.1:54321 HTTPS [server start: d]; // 127.0.0.1:1234 HTTPS
/* /*
* Simple GET via HTTPS without authorization with empty response's body and * Simple GET via HTTPS without authorization with empty response's body and
@ -67,7 +67,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... no auth...GET https://localhost:54321/withoutauth"); PASS([testCase isSuccess], "HTTPS... no auth...GET https://localhost:1234/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -95,7 +95,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... no auth... response 400... GET https://localhost:54321/400/withoutauth"); PASS([testCase isSuccess], "HTTPS... no auth... response 400... GET https://localhost:1234/400/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -125,7 +125,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... no auth... payload... response 400 .... POST https://localhost:54321/400/withoutauth"); PASS([testCase isSuccess], "HTTPS... no auth... payload... response 400 .... POST https://localhost:1234/400/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);
@ -156,7 +156,7 @@ int main(int argc, char **argv, char **env)
nil]; nil];
[testCase setUpTest: d]; [testCase setUpTest: d];
[testCase startTest: d]; [testCase startTest: d];
PASS([testCase isSuccess], "HTTPS... no auth... redirecting... GET https://localhost:54321/301/withoutauth"); PASS([testCase isSuccess], "HTTPS... no auth... redirecting... GET https://localhost:1234/301/withoutauth");
[testCase tearDownTest: d]; [testCase tearDownTest: d];
DESTROY(testCase); DESTROY(testCase);

View file

@ -2,8 +2,8 @@
#if GNUSTEP #if GNUSTEP
#define PORT_LISTEN 54321 #define PORT_LISTEN 1234
#define LOCATION200 @"http://localhost:54321/200" #define LOCATION200 @"http://localhost:1234/200"
@interface StatusServer : NSObject @interface StatusServer : NSObject
{ {

View file

@ -22,7 +22,7 @@ int main(int argc, char **argv)
NSData *resp; NSData *resp;
NSData *rxd; NSData *rxd;
url = [NSURL URLWithString: @"http://localhost:54321/200"]; url = [NSURL URLWithString: @"http://localhost:1234/200"];
cls = [NSURLHandle URLHandleClassForURL: url]; cls = [NSURLHandle URLHandleClassForURL: url];
resp = [NSData dataWithBytes: "Hello\r\n" length: 7]; resp = [NSData dataWithBytes: "Hello\r\n" length: 7];
@ -45,13 +45,13 @@ int main(int argc, char **argv)
PASS([handle status] == NSURLHandleLoadSucceeded, PASS([handle status] == NSURLHandleLoadSucceeded,
"200 - status: Handle load succeeded") ; "200 - status: Handle load succeeded") ;
url = [NSURL URLWithString: @"http://localhost:54321/401"]; url = [NSURL URLWithString: @"http://localhost:1234/401"];
handle = [[[cls alloc] initWithURL: url cached: NO] autorelease]; handle = [[[cls alloc] initWithURL: url cached: NO] autorelease];
rxd = [handle loadInForeground]; rxd = [handle loadInForeground];
PASS([handle status] == NSURLHandleNotLoaded, PASS([handle status] == NSURLHandleNotLoaded,
"401 - status: Handle load not loaded (unanswered auth challenge)"); "401 - status: Handle load not loaded (unanswered auth challenge)");
url = [NSURL URLWithString: @"http://localhost:54321/404"]; url = [NSURL URLWithString: @"http://localhost:1234/404"];
handle = [[[cls alloc] initWithURL: url cached: NO] autorelease]; handle = [[[cls alloc] initWithURL: url cached: NO] autorelease];
rxd = [handle loadInForeground]; rxd = [handle loadInForeground];
PASS([handle status] == NSURLHandleNotLoaded, PASS([handle status] == NSURLHandleNotLoaded,