@@ 28-45 (lines=18) @@ | ||
25 | ||
26 | class CredentialsAuthMiddlewareTest extends TestCase |
|
27 | { |
|
28 | public function testKeyAndSecretIsPassedToParams() |
|
29 | { |
|
30 | $handler = new MockHandler([ |
|
31 | function (RequestInterface $request, array $options) { |
|
32 | $this->assertEquals('key', $options['query']['client_id']); |
|
33 | $this->assertEquals('client_secret', $options['query']['client_secret']); |
|
34 | return new Response(200); |
|
35 | }, |
|
36 | ]); |
|
37 | ||
38 | $stack = new HandlerStack($handler); |
|
39 | $stack->push(CredentialsAuthMiddleware::middleware('key', 'client_secret')); |
|
40 | ||
41 | $comp = $stack->resolve(); |
|
42 | ||
43 | $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'credentials']); |
|
44 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
45 | } |
|
46 | ||
47 | public function testKeySecretAndUserKeyIsPassedToParams() |
|
48 | { |
|
@@ 47-64 (lines=18) @@ | ||
44 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
45 | } |
|
46 | ||
47 | public function testKeySecretAndUserKeyIsPassedToParams() |
|
48 | { |
|
49 | $handler = new MockHandler([ |
|
50 | function (RequestInterface $request, array $options) { |
|
51 | $this->assertEquals('user', $options['query']['client_id']); |
|
52 | $this->assertEquals('client_secret', $options['query']['client_secret']); |
|
53 | return new Response(200); |
|
54 | }, |
|
55 | ]); |
|
56 | ||
57 | $stack = new HandlerStack($handler); |
|
58 | $stack->push(CredentialsAuthMiddleware::middleware('key', 'client_secret', 'user')); |
|
59 | ||
60 | $comp = $stack->resolve(); |
|
61 | ||
62 | $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'credentials']); |
|
63 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
64 | } |
|
65 | ||
66 | public function testAccessors() |
|
67 | { |
|
@@ 75-94 (lines=20) @@ | ||
72 | static::assertEquals('user', $auth->getUserKey()); |
|
73 | } |
|
74 | ||
75 | public function testSubscriberDoesNotDoAnythingForNonHttpsRequests() |
|
76 | { |
|
77 | $handler = new MockHandler([ |
|
78 | function (RequestInterface $request, array $options) { |
|
79 | if (isset($options['query'])) { |
|
80 | $this->assertNotContains('client_id', $options['query']); |
|
81 | $this->assertNotContains('client_secret', $options['query']); |
|
82 | } |
|
83 | return new Response(200); |
|
84 | }, |
|
85 | ]); |
|
86 | ||
87 | $stack = new HandlerStack($handler); |
|
88 | $stack->push(CredentialsAuthMiddleware::middleware('key', 'secret', 'user')); |
|
89 | ||
90 | $comp = $stack->resolve(); |
|
91 | ||
92 | $promise = $comp(new Request('GET', 'http://example.com'), ['auth' => 'credentials']); |
|
93 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
94 | } |
|
95 | ||
96 | public function testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests() |
|
97 | { |
|
@@ 96-115 (lines=20) @@ | ||
93 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
94 | } |
|
95 | ||
96 | public function testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests() |
|
97 | { |
|
98 | $handler = new MockHandler([ |
|
99 | function (RequestInterface $request, array $options) { |
|
100 | if (isset($options['query'])) { |
|
101 | $this->assertNotContains('client_id', $options['query']); |
|
102 | $this->assertNotContains('client_secret', $options['query']); |
|
103 | } |
|
104 | return new Response(200); |
|
105 | }, |
|
106 | ]); |
|
107 | ||
108 | $stack = new HandlerStack($handler); |
|
109 | $stack->push(CredentialsAuthMiddleware::middleware('key', 'secret', 'user')); |
|
110 | ||
111 | $comp = $stack->resolve(); |
|
112 | ||
113 | $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'oauth']); |
|
114 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
115 | } |
|
116 | } |
|
117 |
@@ 28-45 (lines=18) @@ | ||
25 | ||
26 | class HttpsAuthMiddlewareTest extends TestCase |
|
27 | { |
|
28 | public function testKeyAndSecretIsPassedToParams() |
|
29 | { |
|
30 | $handler = new MockHandler([ |
|
31 | function (RequestInterface $request, array $options) { |
|
32 | $this->assertEquals('key', $options['query']['apiKey']); |
|
33 | $this->assertEquals('secret', $options['query']['secret']); |
|
34 | return new Response(200); |
|
35 | }, |
|
36 | ]); |
|
37 | ||
38 | $stack = new HandlerStack($handler); |
|
39 | $stack->push(HttpsAuthMiddleware::middleware('key', 'secret')); |
|
40 | ||
41 | $comp = $stack->resolve(); |
|
42 | ||
43 | $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'gigya']); |
|
44 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
45 | } |
|
46 | ||
47 | public function testKeySecretAndUserKeyIsPassedToParams() |
|
48 | { |
|
@@ 76-95 (lines=20) @@ | ||
73 | static::assertEquals('user', $auth->getUserKey()); |
|
74 | } |
|
75 | ||
76 | public function testSubscriberDoesNotDoAnythingForNonHttpsRequests() |
|
77 | { |
|
78 | $handler = new MockHandler([ |
|
79 | function (RequestInterface $request, array $options) { |
|
80 | if (isset($options['query'])) { |
|
81 | $this->assertNotContains('apiKey', $options['query']); |
|
82 | $this->assertNotContains('secret', $options['query']); |
|
83 | } |
|
84 | return new Response(200); |
|
85 | }, |
|
86 | ]); |
|
87 | ||
88 | $stack = new HandlerStack($handler); |
|
89 | $stack->push(HttpsAuthMiddleware::middleware('key', 'secret', 'user')); |
|
90 | ||
91 | $comp = $stack->resolve(); |
|
92 | ||
93 | $promise = $comp(new Request('GET', 'http://example.com'), ['auth' => 'gigya']); |
|
94 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
95 | } |
|
96 | ||
97 | public function testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests() |
|
98 | { |
|
@@ 97-116 (lines=20) @@ | ||
94 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
95 | } |
|
96 | ||
97 | public function testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests() |
|
98 | { |
|
99 | $handler = new MockHandler([ |
|
100 | function (RequestInterface $request, array $options) { |
|
101 | if (isset($options['query'])) { |
|
102 | $this->assertNotContains('apiKey', $options['query']); |
|
103 | $this->assertNotContains('secret', $options['query']); |
|
104 | } |
|
105 | return new Response(200); |
|
106 | }, |
|
107 | ]); |
|
108 | ||
109 | $stack = new HandlerStack($handler); |
|
110 | $stack->push(HttpsAuthMiddleware::middleware('key', 'secret', 'user')); |
|
111 | ||
112 | $comp = $stack->resolve(); |
|
113 | ||
114 | $promise = $comp(new Request('GET', 'http://example.com'), ['auth' => 'oauth']); |
|
115 | $this->assertInstanceOf(PromiseInterface::class, $promise); |
|
116 | } |
|
117 | } |
|
118 |