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];
if (port == 0) port = 54321;
if (port == 0) port = 1234;
file = [defs stringForKey: @"FileName"];
RETAIN(file);

View file

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

View file

@ -30,7 +30,7 @@ int main()
arguments: [NSArray arrayWithObjects:
@"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"54321",
@"-Port", @"1234",
@"-Count", @"1",
nil]];
if (t != nil)
@ -43,7 +43,7 @@ int main()
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
u = [NSURL URLWithString: @"http://localhost:54321/chunked"];
u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
// Talk to server.
data = [u resourceDataUsingCache: NO];
// Get status code
@ -58,7 +58,7 @@ int main()
arguments: [NSArray arrayWithObjects:
@"-FileName", @"Chunked.dat",
@"-FileHdrs", @"YES", // Headers are in file
@"-Port", @"54321",
@"-Port", @"1234",
@"-Count", @"1",
nil]];
if (t != nil)
@ -74,7 +74,7 @@ int main()
// Pause to allow server subtask to set up.
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
u = [NSURL URLWithString: @"http://localhost:54321/chunked"];
u = [NSURL URLWithString: @"http://localhost:1234/chunked"];
request = [NSURLRequest requestWithURL: u];
response = nil;
@ -91,7 +91,7 @@ int main()
[t waitUntilExit];
}
url = [NSURL URLWithString: @"http://localhost:54321/"];
url = [NSURL URLWithString: @"http://localhost:1234/"];
/* Ask the 'respond' helper to send back a response containing
* '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.
*/
u = [NSURL URLWithString: [NSString stringWithFormat:
@"http://localhost:54321/%d", i % 18]];
@"http://localhost:1234/%d", i % 18]];
// Talk to server.
data = [u resourceDataUsingCache: NO];
// Get status code

View file

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

View file

@ -13,7 +13,7 @@
* test.
*
* 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:]
* 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).
* Default: NO
* 'Address' - the address of the remote side.
* Default: localhost
* Default: 127.0.0.1
* 'Port' - the port of the remote side.
* Default: 54321
* Default: 1234
* 'AuxPort' - the port of the auxilliary remote side (where the connection
* to be redirected).
* Default: 54322
* Default: 1235
* 'Protocol' - the network protocol (supports currently http, https).
* Default: http
* 'Path' - the path of the URL.

View file

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

View file

@ -13,7 +13,7 @@
* It is designed to call the delegate's callbacks (if implemented) of
* the TestWebServerDelegate protocol for every request made to
* 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
* 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
@ -30,7 +30,7 @@
* @"https", @"Protocol",
* nil];
* TestWebServer *server = [[TestWebServer alloc] initWithAddress: @"127.0.0.1"
* port: @"54321"
* port: @"1234"
* mode: NO
* extra: extra];
* ADelegateClass *del = [ADelegateClass new];
@ -72,7 +72,7 @@
* 301 "Redirect to <URL>"
* Returns in the header 'Location' a new <URL> which by default
* 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).
* 400 "You have issued a request with invalid data"
* 401 "Invalid login or password"

View file

@ -27,7 +27,7 @@
/* default 'constants' */
#define DEFAULTADDRESS @"127.0.0.1"
#define DEFAULTPORT @"54321"
#define DEFAULTPORT @"1234"
#define DEFAULTMODE NO
#define DEFAULTLOGIN @"login"
#define DEFAULTPASSWORD @"password"
@ -288,7 +288,7 @@
}
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 *urlString = [NSString stringWithFormat: @"%@://%@:%@/",
_isSecure ? @"https" : @"http",

View file

@ -3,25 +3,25 @@
* Author: Sergei Golovin <Golovin.SV@gmail.com>
*
* 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:
*
* 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:
*
* --2014-08-13 12:08:01-- http://localhost:54321/301
* Resolving localhost (localhost)... 127.0.0.1
* Connecting to localhost (localhost)|127.0.0.1|:54321... connected.
* --2014-08-13 12:08:01-- http://127.0.0.1:1234/301
* Resolving 127.0.0.1 (localhost)... 127.0.0.1
* Connecting to 127.0.0.1 (localhost)|127.0.0.1|:1234... connected.
* 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
* Location: http://127.0.0.1:54322/ [following]
* --2014-08-13 12:08:01-- http://127.0.0.1:54322/
* Connecting to 127.0.0.1:54322... connected.
* Location: http://127.0.0.1:1235/ [following]
* --2014-08-13 12:08:01-- http://127.0.0.1:1235/
* Connecting to 127.0.0.1:1235... connected.
* 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
* Length: 0
* Saving to: STDOUT
@ -63,19 +63,21 @@ int main(int argc, char **argv, char **env)
d = [NSDictionary dictionaryWithObjectsAndKeys:
// @"https", @"Protocol",
nil];
server1 = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost"
port: @"54321"
server1 = [[[testClass testWebServerClass] alloc]
initWithAddress: @"127.0.0.1"
port: @"1234"
mode: NO
extra: d];
[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"
port: @"54322"
server2 = [[[testClass testWebServerClass] alloc]
initWithAddress: @"127.0.0.1"
port: @"1235"
mode: NO
extra: d];
[server2 setDebug: debug];
[server2 start: d]; // 127.0.0.1:54322 HTTP
[server2 start: d]; // 127.0.0.1:1235 HTTP
while (YES)
{

View file

@ -35,7 +35,7 @@ int main(int argc, char **argv, char **env)
// create a shared TestWebServer instance for performance
server = [[testClass testWebServerClass] new];
[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
@ -49,7 +49,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: d];
[testCase startTest: d];
PASS([testCase isSuccess], "GET http://localhost:54321");
PASS([testCase isSuccess], "GET http://localhost:1234/");
[testCase tearDownTest: d];
DESTROY(testCase);
@ -68,7 +68,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -89,7 +89,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -115,7 +115,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);

View file

@ -39,12 +39,13 @@ int main(int argc, char **argv, char **env)
@"HTTPS", @"Protocol",
nil];
// create a shared TestWebServer instance for performance
server = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost"
port: @"54321"
server = [[[testClass testWebServerClass] alloc]
initWithAddress: @"127.0.0.1"
port: @"1234"
mode: NO
extra: d];
[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
@ -58,7 +59,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -73,11 +74,11 @@ int main(int argc, char **argv, char **env)
server, @"Instance", // we use the shared TestWebServer instance
@"400", @"Path", // request the handler responding with 400
@"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];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -92,13 +93,13 @@ int main(int argc, char **argv, char **env)
server, @"Instance", // we use the shared TestWebServer instance
@"400", @"Path", // request the handler responding with 400
@"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
@"POST", @"Method", // use POST
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -124,7 +125,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);

View file

@ -35,7 +35,7 @@ int main(int argc, char **argv, char **env)
// create a shared TestWebServer instance for performance
server = [[testClass testWebServerClass] new];
[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
@ -59,7 +59,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -87,7 +87,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -117,7 +117,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -148,7 +148,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);

View file

@ -39,11 +39,11 @@ int main(int argc, char **argv, char **env)
nil];
// create a shared TestWebServer instance for performance
server = [[[testClass testWebServerClass] alloc] initWithAddress: @"localhost"
port: @"54321"
port: @"1234"
mode: NO
extra: d];
[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
@ -67,7 +67,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -95,7 +95,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -125,7 +125,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);
@ -156,7 +156,7 @@ int main(int argc, char **argv, char **env)
nil];
[testCase setUpTest: 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];
DESTROY(testCase);

View file

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

View file

@ -22,7 +22,7 @@ int main(int argc, char **argv)
NSData *resp;
NSData *rxd;
url = [NSURL URLWithString: @"http://localhost:54321/200"];
url = [NSURL URLWithString: @"http://localhost:1234/200"];
cls = [NSURLHandle URLHandleClassForURL: url];
resp = [NSData dataWithBytes: "Hello\r\n" length: 7];
@ -45,13 +45,13 @@ int main(int argc, char **argv)
PASS([handle status] == NSURLHandleLoadSucceeded,
"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];
rxd = [handle loadInForeground];
PASS([handle status] == NSURLHandleNotLoaded,
"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];
rxd = [handle loadInForeground];
PASS([handle status] == NSURLHandleNotLoaded,