Skip to content

Commit 73a3375

Browse files
committed
be more defensive, explain why POST /session fails
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 443aaee commit 73a3375

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

tests/integration/GithubOauthIntegrationTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,18 @@ private function loginToGitHub(string $authorizeUrl): array {
202202
$loginStatus = $loginResponse->getStatusCode();
203203
$loginBody = $loginResponse->getBody()->getContents();
204204

205-
if ($loginStatus === Http::STATUS_OK && str_contains($loginBody, 'Two-factor authentication')) {
205+
if ($loginStatus !== Http::STATUS_OK) {
206+
$this->fail('GitHub login request to /session failed with status ' . $loginStatus . '. Response body: ' . $loginBody);
207+
}
208+
209+
if (str_contains($loginBody, 'Two-factor authentication')) {
206210
return [
207211
'status' => '2fa_required',
208212
'body' => $loginBody,
209213
];
210214
}
211215

212-
if ($loginStatus === Http::STATUS_OK && str_contains($loginBody, 'Incorrect username or password')) {
216+
if (str_contains($loginBody, 'Incorrect username or password')) {
213217
return [
214218
'status' => 'invalid_credentials',
215219
'body' => $loginBody,
@@ -251,7 +255,7 @@ private function handleAuthorizePage(string $authorizeUrl): string {
251255
}
252256

253257
if (empty($formParams)) {
254-
$this->fail('Could not find OAuth authorize form on page. The authorize page HTML may have changed or login did not succeed. Body: ' . $body);
258+
$this->fail('Could not find OAuth authorize form on page. The authorize page HTML may have changed or login did not succeed. URL of the authorize page:' . $authorizeUrl . ' Body: ' . $body);
255259
}
256260

257261
$authorizeResponse = $this->client->post('https://github.com/login/oauth/authorize', [
@@ -301,6 +305,7 @@ public function testOAuthLogin(): void {
301305
$this->fail('Invalid GitHub credentials');
302306
}
303307

308+
echo 'STATUS of login: ' . $loginResult['status'] . "\n\n";
304309
$redirectUrl = null;
305310
if ($loginResult['status'] === 'authorize_page' || $loginResult['status'] === 'logged_in') {
306311
$redirectUrl = $this->handleAuthorizePage($authorizeUrl);

0 commit comments

Comments
 (0)