|
6 | 6 | use Olssonm\VeryBasicAuth\Tests\Fixtures\CustomResponseHandler;
|
7 | 7 |
|
8 | 8 | use function Pest\Laravel\get;
|
| 9 | +use function Pest\Laravel\withHeader; |
9 | 10 |
|
10 | 11 | test('basic auth filter is set', function () {
|
11 | 12 | expect(in_array(VeryBasicAuth::class, $this->app->router->getMiddleware()))->toBeTrue();
|
|
35 | 36 | });
|
36 | 37 |
|
37 | 38 | test('request with incorrect credentials fails - text/html', function () {
|
38 |
| - $response = $this->withHeaders([ |
| 39 | + $response = withHeaders([ |
39 | 40 | 'PHP_AUTH_USER' => str_random(20),
|
40 | 41 | 'PHP_AUTH_PW' => str_random(20),
|
41 | 42 | ])->get('/');
|
|
47 | 48 | });
|
48 | 49 |
|
49 | 50 | test('request with incorrect credentials fails - json', function () {
|
50 |
| - $response = $this->withHeaders([ |
| 51 | + $response = withHeaders([ |
51 | 52 | 'PHP_AUTH_USER' => str_random(20),
|
52 | 53 | 'PHP_AUTH_PW' => str_random(20),
|
53 | 54 | 'Accept' => 'application/json',
|
|
63 | 64 | });
|
64 | 65 |
|
65 | 66 | test('request with incorrect credentials fails - view', function () {
|
66 |
| - |
67 | 67 | config()->set('very_basic_auth.error_view', 'very_basic_auth::default');
|
68 | 68 |
|
69 |
| - $response = $this->withHeaders([ |
| 69 | + $response = withHeaders([ |
70 | 70 | 'PHP_AUTH_USER' => str_random(20),
|
71 | 71 | 'PHP_AUTH_PW' => str_random(20),
|
72 | 72 | ])->get('/');
|
|
79 | 79 | });
|
80 | 80 |
|
81 | 81 | test('request with correct credentials passes', function () {
|
82 |
| - $response = $this->withHeaders([ |
| 82 | + $response = withHeaders([ |
83 | 83 | 'PHP_AUTH_USER' => config('very_basic_auth.user'),
|
84 | 84 | 'PHP_AUTH_PW' => config('very_basic_auth.password'),
|
85 | 85 | ])->get('/');
|
86 | 86 |
|
87 |
| - $this->assertEquals(200, $response->getStatusCode()); |
88 |
| - $this->assertEquals('ok', $response->getContent()); |
| 87 | + expect($response->getStatusCode())->toEqual(200); |
| 88 | + expect($response->getContent())->toEqual('ok'); |
89 | 89 | });
|
90 | 90 |
|
91 | 91 | test('environments', function () {
|
92 | 92 | config()->set('very_basic_auth.envs', ['production']);
|
93 |
| - $this->get('/')->assertStatus(200); |
| 93 | + get('/')->assertStatus(200); |
94 | 94 |
|
95 | 95 | config()->set('very_basic_auth.envs', ['local']);
|
96 |
| - $this->get('/')->assertStatus(200); |
| 96 | + get('/')->assertStatus(200); |
97 | 97 |
|
98 | 98 | config()->set('very_basic_auth.envs', ['*']);
|
99 |
| - $this->get('/')->assertStatus(401); |
| 99 | + get('/')->assertStatus(401); |
100 | 100 |
|
101 | 101 | config()->set('very_basic_auth.envs', ['testing']);
|
102 |
| - $this->get('/')->assertStatus(401); |
| 102 | + get('/')->assertStatus(401); |
103 | 103 | });
|
104 | 104 |
|
105 | 105 | test('request with incorrect inline credentials fails', function () {
|
106 |
| - $response = $this->withHeaders([ |
| 106 | + $response = withHeaders([ |
107 | 107 | 'PHP_AUTH_USER' => str_random(20),
|
108 | 108 | 'PHP_AUTH_PW' => str_random(20),
|
109 | 109 | ])->get('/inline');
|
110 | 110 |
|
111 |
| - $this->assertEquals(401, $response->getStatusCode()); |
112 |
| - $this->assertEquals(config('very_basic_auth.error_message'), $response->getContent()); |
| 111 | + expect($response->getStatusCode())->toEqual(401); |
| 112 | + expect($response->getContent())->toEqual(config('very_basic_auth.error_message')); |
113 | 113 | });
|
114 | 114 |
|
115 | 115 | test('request with correct inline credentials passes', function () {
|
116 |
| - $response = $this->withHeaders([ |
| 116 | + $response = withHeaders([ |
117 | 117 | 'PHP_AUTH_USER' => config('very_basic_auth.user'),
|
118 | 118 | 'PHP_AUTH_PW' => config('very_basic_auth.password'),
|
119 | 119 | ])->get('/inline');
|
120 | 120 |
|
121 |
| - $this->assertEquals(200, $response->getStatusCode()); |
122 |
| - $this->assertEquals('ok', $response->getContent()); |
| 121 | + expect($response->getStatusCode())->toEqual(200); |
| 122 | + expect($response->getContent())->toEqual('ok'); |
123 | 123 | });
|
124 | 124 |
|
125 | 125 | test('test response handlers', function () {
|
|
131 | 131 |
|
132 | 132 | $response = get('/test');
|
133 | 133 |
|
134 |
| - $this->assertEquals(401, $response->getStatusCode()); |
135 |
| - $this->assertEquals('Custom response', $response->getContent()); |
| 134 | + expect($response->getStatusCode())->toEqual(401); |
| 135 | + expect($response->getContent())->toEqual('Custom reponse'); |
136 | 136 |
|
137 | 137 | // Default response handler
|
138 | 138 | app()->bind(
|
|
142 | 142 |
|
143 | 143 | $response = get('/test');
|
144 | 144 |
|
145 |
| - $this->assertEquals(401, $response->getStatusCode()); |
146 |
| - $this->assertEquals(config('very_basic_auth.error_message'), $response->getContent()); |
| 145 | + expect($response->getStatusCode())->toEqual(401); |
| 146 | + expect($response->getContent())->toEqual(config('very_basic_auth.error_message')); |
147 | 147 | });
|
0 commit comments