@@ -47,6 +47,16 @@ using httpserver::string_response;
47
47
using httpserver::http_resource;
48
48
using httpserver::http_request;
49
49
50
+ #ifdef HTTPSERVER_PORT
51
+ #define PORT HTTPSERVER_PORT
52
+ #else
53
+ #define PORT 8080
54
+ #endif // PORT
55
+
56
+ #define STR2 (p ) #p
57
+ #define STR (p ) STR2(p)
58
+ #define PORT_STRING STR (PORT)
59
+
50
60
size_t writefunc(void *ptr, size_t size, size_t nmemb, std::string *s) {
51
61
s->append (reinterpret_cast <char *>(ptr), size*nmemb);
52
62
return size*nmemb;
@@ -86,10 +96,10 @@ LT_BEGIN_SUITE(authentication_suite)
86
96
LT_END_SUITE (authentication_suite)
87
97
88
98
LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
89
- webserver ws = create_webserver(8080 );
99
+ webserver ws = create_webserver(PORT );
90
100
91
101
user_pass_resource user_pass;
92
- ws.register_resource(" base" , &user_pass);
102
+ LT_ASSERT_EQ ( true , ws.register_resource(" base" , &user_pass) );
93
103
ws.start(false );
94
104
95
105
curl_global_init (CURL_GLOBAL_ALL);
@@ -98,7 +108,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
98
108
CURLcode res;
99
109
curl_easy_setopt (curl, CURLOPT_USERNAME, " myuser" );
100
110
curl_easy_setopt (curl, CURLOPT_PASSWORD, " mypass" );
101
- curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080 /base" );
111
+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:" PORT_STRING " /base" );
102
112
curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
103
113
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
104
114
curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
@@ -111,10 +121,10 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
111
121
LT_END_AUTO_TEST (base_auth)
112
122
113
123
LT_BEGIN_AUTO_TEST(authentication_suite, base_auth_fail)
114
- webserver ws = create_webserver(8080 );
124
+ webserver ws = create_webserver(PORT );
115
125
116
126
user_pass_resource user_pass;
117
- ws.register_resource(" base" , &user_pass);
127
+ LT_ASSERT_EQ ( true , ws.register_resource(" base" , &user_pass) );
118
128
ws.start(false );
119
129
120
130
curl_global_init (CURL_GLOBAL_ALL);
@@ -123,7 +133,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth_fail)
123
133
CURLcode res;
124
134
curl_easy_setopt (curl, CURLOPT_USERNAME, " myuser" );
125
135
curl_easy_setopt (curl, CURLOPT_PASSWORD, " wrongpass" );
126
- curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080 /base" );
136
+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:" PORT_STRING " /base" );
127
137
curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
128
138
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
129
139
curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
@@ -141,12 +151,12 @@ LT_END_AUTO_TEST(base_auth_fail)
141
151
#ifndef _WINDOWS
142
152
143
153
LT_BEGIN_AUTO_TEST (authentication_suite, digest_auth)
144
- webserver ws = create_webserver(8080 )
154
+ webserver ws = create_webserver(PORT )
145
155
.digest_auth_random(" myrandom" )
146
156
.nonce_nc_size(300 );
147
157
148
158
digest_resource digest;
149
- ws.register_resource(" base" , &digest);
159
+ LT_ASSERT_EQ ( true , ws.register_resource(" base" , &digest) );
150
160
ws.start(false );
151
161
152
162
#if defined(_WINDOWS)
@@ -164,7 +174,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
164
174
#else
165
175
curl_easy_setopt (curl, CURLOPT_USERPWD, " myuser:mypass" );
166
176
#endif
167
- curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080 /base" );
177
+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:" PORT_STRING " /base" );
168
178
curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
169
179
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
170
180
curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
@@ -181,12 +191,12 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
181
191
LT_END_AUTO_TEST (digest_auth)
182
192
183
193
LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth_wrong_pass)
184
- webserver ws = create_webserver(8080 )
194
+ webserver ws = create_webserver(PORT )
185
195
.digest_auth_random(" myrandom" )
186
196
.nonce_nc_size(300 );
187
197
188
198
digest_resource digest;
189
- ws.register_resource(" base" , &digest);
199
+ LT_ASSERT_EQ ( true , ws.register_resource(" base" , &digest) );
190
200
ws.start(false );
191
201
192
202
#if defined(_WINDOWS)
@@ -204,7 +214,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth_wrong_pass)
204
214
#else
205
215
curl_easy_setopt (curl, CURLOPT_USERPWD, " myuser:wrongpass" );
206
216
#endif
207
- curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080 /base" );
217
+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:" PORT_STRING " /base" );
208
218
curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
209
219
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
210
220
curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
0 commit comments