@@ 56-73 (lines=18) @@ | ||
53 | /** |
|
54 | * @test |
|
55 | */ |
|
56 | public function canCreateTokenFromBearerHeaderByDefault() |
|
57 | { |
|
58 | $tokenString = 'TheJwtToken'; |
|
59 | ||
60 | /** @var \PHPUnit_Framework_MockObject_MockObject $mock */ |
|
61 | $mock = $this->authenticationManagerMock; |
|
62 | $mock->expects($this->once()) |
|
63 | ->method('authenticate') |
|
64 | ->with($this->callback(function (JwtAuthenticationToken $token) use ($tokenString) { |
|
65 | return $token->getCredentials() === $tokenString; |
|
66 | })); |
|
67 | ||
68 | (new JwtAuthenticationListener($this->tokenStorageMock, $this->authenticationManagerMock)) |
|
69 | ->handle($this->createKernelEventWithRequest( |
|
70 | $this->createRequestWithServerVar('HTTP_AUTHORIZATION', "Bearer $tokenString")) |
|
71 | ); |
|
72 | ||
73 | } |
|
74 | ||
75 | /** |
|
76 | * @test |
|
@@ 78-94 (lines=17) @@ | ||
75 | /** |
|
76 | * @test |
|
77 | */ |
|
78 | public function canCreateTokenFromAuthHeaderWithoutBearerPrefixByDefault() |
|
79 | { |
|
80 | $tokenString = 'TheJwtToken'; |
|
81 | ||
82 | /** @var \PHPUnit_Framework_MockObject_MockObject $mock */ |
|
83 | $mock = $this->authenticationManagerMock; |
|
84 | $mock->expects($this->once()) |
|
85 | ->method('authenticate') |
|
86 | ->with($this->callback(function (JwtAuthenticationToken $token) use ($tokenString) { |
|
87 | return $token->getCredentials() === $tokenString; |
|
88 | })); |
|
89 | ||
90 | (new JwtAuthenticationListener($this->tokenStorageMock, $this->authenticationManagerMock)) |
|
91 | ->handle($this->createKernelEventWithRequest( |
|
92 | $this->createRequestWithServerVar('HTTP_AUTHORIZATION', $tokenString)) |
|
93 | ); |
|
94 | } |
|
95 | ||
96 | /** |
|
97 | * @test |
|
@@ 99-115 (lines=17) @@ | ||
96 | /** |
|
97 | * @test |
|
98 | */ |
|
99 | public function canCreateTokenFromCustomHeader() |
|
100 | { |
|
101 | $tokenString = 'TheJwtToken'; |
|
102 | ||
103 | /** @var \PHPUnit_Framework_MockObject_MockObject $mock */ |
|
104 | $mock = $this->authenticationManagerMock; |
|
105 | $mock->expects($this->once()) |
|
106 | ->method('authenticate') |
|
107 | ->with($this->callback(function (JwtAuthenticationToken $token) use ($tokenString) { |
|
108 | return $token->getCredentials() === $tokenString; |
|
109 | })); |
|
110 | ||
111 | (new JwtAuthenticationListener($this->tokenStorageMock, $this->authenticationManagerMock, 'X-Token')) |
|
112 | ->handle($this->createKernelEventWithRequest( |
|
113 | $this->createRequestWithServerVar('HTTP_X_TOKEN', $tokenString)) |
|
114 | ); |
|
115 | } |
|
116 | ||
117 | /** |
|
118 | * @test |