Skip to content

Commit 9b3fe67

Browse files
committed
Ensure the method is always uppercase for requests
1 parent d6e6e97 commit 9b3fe67

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/Requests/Payload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function generateFromPsr7Request(Psr7Request $request) : string
4646

4747
return json_encode([
4848
'id' => (string) $id,
49-
'method' => $this->request->getMethod(),
49+
'method' => strtoupper($this->request->getMethod()),
5050
'timestamp' => $timestamp,
5151
'uri' => (string) $this->request->getUri(),
5252
'content' => $this->request->getBody()->getContents()
@@ -69,7 +69,7 @@ protected function generateFromIlluminateRequest(IlluminateRequest $request) : s
6969

7070
return json_encode([
7171
'id' => (string) $id,
72-
'method' => $this->request->getMethod(),
72+
'method' => strtoupper($this->request->getMethod()),
7373
'timestamp' => $timestamp,
7474
'uri' => (string) $this->request->fullUrl(),
7575
'content' => $this->request->getContent()

tests/Requests/PayloadTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,72 @@ public function it_translates_an_illuminate_request_to_a_json_encoded_string()
103103
$this->assertEquals($expected, (string) new Payload($request));
104104
}
105105

106+
/**
107+
* @test
108+
*/
109+
public function it_upper_cases_the_illuminate_request_method()
110+
{
111+
$now = (string)Carbon::now();
112+
$id = (string)Uuid::uuid4();
113+
114+
$uri = 'https://localhost';
115+
$method = 'get';
116+
$parameters = [];
117+
$cookies = [];
118+
$files = [];
119+
$server = [
120+
'HTTP_X-SIGNED-ID' => $id,
121+
'HTTP_X-SIGNED-TIMESTAMP' => $now
122+
];
123+
$content = null;
124+
125+
$request = IlluminateRequest::create(
126+
$uri,
127+
$method,
128+
$parameters,
129+
$cookies,
130+
$files,
131+
$server,
132+
$content
133+
);
134+
135+
$expected = json_encode([
136+
'id' => $id,
137+
'method' => 'GET',
138+
'timestamp' => $now,
139+
'uri' => $uri,
140+
'content' => $request->getContent()
141+
], JSON_UNESCAPED_SLASHES);
142+
143+
$this->assertEquals($expected, (string)new Payload($request));
144+
}
145+
146+
147+
/**
148+
* @test
149+
*/
150+
public function it_upper_cases_the_guzzle_request_method()
151+
{
152+
$now = (string)Carbon::now();
153+
154+
$uri = 'https://localhost';
155+
$id = Uuid::uuid4();
156+
157+
$request = (new GuzzleRequest('get', 'https://localhost', [], 'content'))
158+
->withHeader('X-SIGNED-ID', $id)
159+
->withHeader('X-SIGNED-TIMESTAMP', $now);
160+
161+
$expected = json_encode([
162+
'id' => $id,
163+
'method' => 'GET',
164+
'timestamp' => $now,
165+
'uri' => $uri,
166+
'content' => 'content'
167+
], JSON_UNESCAPED_SLASHES);
168+
169+
$this->assertEquals($expected, (string)new Payload($request));
170+
}
171+
106172
/**
107173
* @test
108174
*/

0 commit comments

Comments
 (0)