Skip to content

Commit 30d6058

Browse files
committed
Clarify origin in examples
1 parent 6f6a23e commit 30d6058

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use Asm89\Stack\CorsService;
4646
$cors = new CorsService(array(
4747
'allowedHeaders' => array('x-allowed-header', 'x-other-allowed-header'),
4848
'allowedMethods' => array('DELETE', 'GET', 'POST', 'PUT'),
49-
'allowedOrigins' => array('localhost'),
49+
'allowedOrigins' => array('http://localhost'),
5050
'allowedOriginsPatterns' => array('/localhost:\d/'),
5151
'exposedHeaders' => false,
5252
'maxAge' => false,

tests/CorsTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ class CorsTest extends TestCase
2525
public function it_does_modify_on_a_request_without_origin()
2626
{
2727
$app = $this->createStackedApp();
28-
$unmodifiedResponse = new Response();
2928

3029
$response = $app->handle(new Request());
3130

32-
$this->assertEquals('localhost', $response->headers->get('Access-Control-Allow-Origin'));
31+
$this->assertEquals('http://localhost', $response->headers->get('Access-Control-Allow-Origin'));
3332
}
3433

3534
/**
@@ -59,7 +58,7 @@ public function it_returns_allow_origin_header_on_valid_actual_request()
5958
$response = $app->handle($request);
6059

6160
$this->assertTrue($response->headers->has('Access-Control-Allow-Origin'));
62-
$this->assertEquals('localhost', $response->headers->get('Access-Control-Allow-Origin'));
61+
$this->assertEquals('http://localhost', $response->headers->get('Access-Control-Allow-Origin'));
6362
}
6463

6564
/**
@@ -238,13 +237,13 @@ public function it_doesnt_add_a_vary_header_when_simple_origins()
238237
public function it_adds_a_vary_header_when_multiple_origins()
239238
{
240239
$app = $this->createStackedApp(array(
241-
'allowedOrigins' => array('localhost', 'http://example.com')
240+
'allowedOrigins' => array('http://localhost', 'http://example.com')
242241
));
243242
$request = $this->createValidActualRequest();
244243

245244
$response = $app->handle($request);
246245

247-
$this->assertEquals('localhost', $response->headers->get('Access-Control-Allow-Origin'));
246+
$this->assertEquals('http://localhost', $response->headers->get('Access-Control-Allow-Origin'));
248247
$this->assertTrue($response->headers->has('Vary'));
249248
}
250249

@@ -278,12 +277,12 @@ public function it_returns_access_control_headers_on_cors_request()
278277
{
279278
$app = $this->createStackedApp();
280279
$request = new Request();
281-
$request->headers->set('Origin', 'localhost');
280+
$request->headers->set('Origin', 'http://localhost');
282281

283282
$response = $app->handle($request);
284283

285284
$this->assertTrue($response->headers->has('Access-Control-Allow-Origin'));
286-
$this->assertEquals('localhost', $response->headers->get('Access-Control-Allow-Origin'));
285+
$this->assertEquals('http://localhost', $response->headers->get('Access-Control-Allow-Origin'));
287286
}
288287

289288
/**
@@ -300,7 +299,7 @@ public function it_returns_access_control_headers_on_cors_request_with_pattern_o
300299
$response = $app->handle($request);
301300

302301
$this->assertTrue($response->headers->has('Access-Control-Allow-Origin'));
303-
$this->assertEquals('localhost', $response->headers->get('Access-Control-Allow-Origin'));
302+
$this->assertEquals('http://localhost', $response->headers->get('Access-Control-Allow-Origin'));
304303
$this->assertTrue($response->headers->has('Vary'));
305304
$this->assertEquals('Origin', $response->headers->get('Vary'));
306305
}
@@ -316,7 +315,7 @@ public function it_returns_access_control_headers_on_valid_preflight_request()
316315
$response = $app->handle($request);
317316

318317
$this->assertTrue($response->headers->has('Access-Control-Allow-Origin'));
319-
$this->assertEquals('localhost', $response->headers->get('Access-Control-Allow-Origin'));
318+
$this->assertEquals('http://localhost', $response->headers->get('Access-Control-Allow-Origin'));
320319
}
321320

322321
/**
@@ -325,7 +324,7 @@ public function it_returns_access_control_headers_on_valid_preflight_request()
325324
public function it_does_not_allow_request_with_origin_not_allowed()
326325
{
327326
$passedOptions = array(
328-
'allowedOrigins' => array('notlocalhost'),
327+
'allowedOrigins' => array('http://notlocalhost'),
329328
);
330329

331330
$service = new CorsService($passedOptions);
@@ -504,15 +503,15 @@ public function it_skips_empty_access_control_request_header()
504503
private function createValidActualRequest()
505504
{
506505
$request = new Request();
507-
$request->headers->set('Origin', 'localhost');
506+
$request->headers->set('Origin', 'http://localhost');
508507

509508
return $request;
510509
}
511510

512511
private function createValidPreflightRequest()
513512
{
514513
$request = new Request();
515-
$request->headers->set('Origin', 'localhost');
514+
$request->headers->set('Origin', 'http://localhost');
516515
$request->headers->set('Access-Control-Request-Method', 'get');
517516
$request->setMethod('OPTIONS');
518517

@@ -524,7 +523,7 @@ private function createStackedApp(array $options = array(), array $responseHeade
524523
$passedOptions = array_merge(array(
525524
'allowedHeaders' => array('x-allowed-header', 'x-other-allowed-header'),
526525
'allowedMethods' => array('delete', 'get', 'post', 'put'),
527-
'allowedOrigins' => array('localhost'),
526+
'allowedOrigins' => array('http://localhost'),
528527
'exposedHeaders' => false,
529528
'maxAge' => false,
530529
'supportsCredentials' => false,

0 commit comments

Comments
 (0)