Skip to content

Commit f1a0cfe

Browse files
committed
Tests for bearer tokens
1 parent ae13724 commit f1a0cfe

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/TokenTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,25 @@ public function testFromQueryString()
262262
$tokenObject = Token::fromQueryString();
263263
$this->assertInstanceOf(Token::class, $tokenObject);
264264
}
265+
266+
public function testFromAuthorizationBearer()
267+
{
268+
$secret = new HsSecret('secret');
269+
$token = 'Bearer ' . Token::create()
270+
->withSigner(SignerFactory::build('HS256'))
271+
->sign($secret)
272+
->toString();
273+
274+
//Possibility 1:
275+
$_SERVER['Authorization'] = $token;
276+
$tokenObject = Token::fromAuthorizationBearer();
277+
$this->assertInstanceOf(Token::class, $tokenObject);
278+
unset($_SERVER['Authorization']);
279+
280+
//Possibility 2:
281+
$_SERVER['HTTP_AUTHORIZATION'] = $token;
282+
$tokenObject = Token::fromAuthorizationBearer();
283+
$this->assertInstanceOf(Token::class, $tokenObject);
284+
unset($_SERVER['HTTP_AUTHORIZATION']);
285+
}
265286
}

0 commit comments

Comments
 (0)