@@ -66,7 +66,7 @@ private function createListener(array $options = array(), $success = true, $matc
66
66
public function testHandleSuccess ()
67
67
{
68
68
$ this ->createListener ();
69
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"username": "dunglas", "password": "foo"} ' );
69
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"username": "dunglas", "password": "foo"} ' );
70
70
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
71
71
72
72
$ this ->listener ->handle ($ event );
@@ -76,7 +76,7 @@ public function testHandleSuccess()
76
76
public function testHandleFailure ()
77
77
{
78
78
$ this ->createListener (array (), false );
79
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"username": "dunglas", "password": "foo"} ' );
79
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"username": "dunglas", "password": "foo"} ' );
80
80
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
81
81
82
82
$ this ->listener ->handle ($ event );
@@ -86,7 +86,7 @@ public function testHandleFailure()
86
86
public function testUsePath ()
87
87
{
88
88
$ this ->createListener (array ('username_path ' => 'user.login ' , 'password_path ' => 'user.pwd ' ));
89
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"user": {"login": "dunglas", "pwd": "foo"}} ' );
89
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"user": {"login": "dunglas", "pwd": "foo"}} ' );
90
90
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
91
91
92
92
$ this ->listener ->handle ($ event );
@@ -96,7 +96,7 @@ public function testUsePath()
96
96
public function testAttemptAuthenticationNoUsername ()
97
97
{
98
98
$ this ->createListener ();
99
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"usr": "dunglas", "password": "foo"} ' );
99
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"usr": "dunglas", "password": "foo"} ' );
100
100
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
101
101
102
102
$ this ->listener ->handle ($ event );
@@ -106,7 +106,7 @@ public function testAttemptAuthenticationNoUsername()
106
106
public function testAttemptAuthenticationNoPassword ()
107
107
{
108
108
$ this ->createListener ();
109
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"username": "dunglas", "pass": "foo"} ' );
109
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"username": "dunglas", "pass": "foo"} ' );
110
110
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
111
111
112
112
$ this ->listener ->handle ($ event );
@@ -116,7 +116,7 @@ public function testAttemptAuthenticationNoPassword()
116
116
public function testAttemptAuthenticationUsernameNotAString ()
117
117
{
118
118
$ this ->createListener ();
119
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"username": 1, "password": "foo"} ' );
119
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"username": 1, "password": "foo"} ' );
120
120
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
121
121
122
122
$ this ->listener ->handle ($ event );
@@ -126,7 +126,7 @@ public function testAttemptAuthenticationUsernameNotAString()
126
126
public function testAttemptAuthenticationPasswordNotAString ()
127
127
{
128
128
$ this ->createListener ();
129
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"username": "dunglas", "password": 1} ' );
129
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"username": "dunglas", "password": 1} ' );
130
130
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
131
131
132
132
$ this ->listener ->handle ($ event );
@@ -137,7 +137,7 @@ public function testAttemptAuthenticationUsernameTooLong()
137
137
{
138
138
$ this ->createListener ();
139
139
$ username = str_repeat ('x ' , Security::MAX_USERNAME_LENGTH + 1 );
140
- $ request = new Request (array (), array (), array (), array (), array (), array (), sprintf ('{"username": "%s", "password": 1} ' , $ username ));
140
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), sprintf ('{"username": "%s", "password": 1} ' , $ username ));
141
141
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
142
142
143
143
$ this ->listener ->handle ($ event );
@@ -147,7 +147,18 @@ public function testAttemptAuthenticationUsernameTooLong()
147
147
public function testDoesNotAttemptAuthenticationIfRequestPathDoesNotMatchCheckPath ()
148
148
{
149
149
$ this ->createListener (array ('check_path ' => '/ ' ), true , false );
150
- $ request = new Request ();
150
+ $ request = new Request (array (), array (), array (), array (), array (), array ('HTTP_CONTENT_TYPE ' => 'application/json ' ));
151
+ $ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
152
+ $ event ->setResponse (new Response ('original ' ));
153
+
154
+ $ this ->listener ->handle ($ event );
155
+ $ this ->assertSame ('original ' , $ event ->getResponse ()->getContent ());
156
+ }
157
+
158
+ public function testDoesNotAttemptAuthenticationIfRequestContentTypeIsNotJson ()
159
+ {
160
+ $ this ->createListener ();
161
+ $ request = new Request (array (), array (), array (), array (), array (), array (), '{"username": "dunglas", "password": "foo"} ' );
151
162
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
152
163
$ event ->setResponse (new Response ('original ' ));
153
164
@@ -158,7 +169,7 @@ public function testDoesNotAttemptAuthenticationIfRequestPathDoesNotMatchCheckPa
158
169
public function testAttemptAuthenticationIfRequestPathMatchesCheckPath ()
159
170
{
160
171
$ this ->createListener (array ('check_path ' => '/ ' ));
161
- $ request = new Request (array (), array (), array (), array (), array (), array (), '{"username": "dunglas", "password": "foo"} ' );
172
+ $ request = new Request (array (), array (), array (), array (), array (), array (' HTTP_CONTENT_TYPE ' => ' application/json ' ), '{"username": "dunglas", "password": "foo"} ' );
162
173
$ event = new GetResponseEvent ($ this ->getMockBuilder (KernelInterface::class)->getMock (), $ request , KernelInterface::MASTER_REQUEST );
163
174
164
175
$ this ->listener ->handle ($ event );
0 commit comments