|
1 | 1 | <?php |
| 2 | + |
| 3 | +use App\Services\SettingsService; |
| 4 | + |
2 | 5 | beforeAll(function () { |
3 | 6 | putenv("ENVIRONMENT=test"); |
4 | 7 | }); |
|
11 | 14 | }); |
12 | 15 |
|
13 | 16 | test('test the blocklist with an exact match', function ($method) { |
14 | | - $caller = "5557778888"; |
15 | | - $_SESSION['override_blocklist'] = $caller; |
| 17 | + $caller = "+15557778888"; |
| 18 | + $settingsService = new SettingsService(); |
| 19 | + $settingsService->set("blocklist", $caller); |
| 20 | + app()->instance(SettingsService::class, $settingsService); |
16 | 21 | $response = $this->call($method, '/', [ |
17 | 22 | "Caller"=>$caller |
18 | 23 | ]); |
|
22 | 27 | ->assertSeeInOrderExact(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
23 | 28 | })->with(['GET', 'POST']); |
24 | 29 |
|
| 30 | +test('test the blocklist with multiple items and an exact match', function ($method) { |
| 31 | + $caller = "+15557778888,+15557778890"; |
| 32 | + $settingsService = new SettingsService(); |
| 33 | + $settingsService->set("blocklist", $caller); |
| 34 | + app()->instance(SettingsService::class, $settingsService); |
| 35 | + $response = $this->call($method, '/', [ |
| 36 | + "Caller"=>"+15557778890" |
| 37 | + ]); |
| 38 | + $response |
| 39 | + ->assertStatus(200) |
| 40 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 41 | + ->assertSeeInOrderExact(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 42 | +})->with(['GET', 'POST']); |
| 43 | + |
25 | 44 | test('test the blocklist without a match', function ($method) { |
26 | | - $caller = "5557778888"; |
27 | | - $_SESSION['override_blocklist'] = $caller; |
| 45 | + $caller = "+15557778888"; |
| 46 | + $settingsService = new SettingsService(); |
| 47 | + $settingsService->set("blocklist", $caller); |
| 48 | + app()->instance(SettingsService::class, $settingsService); |
28 | 49 | $response = $this->call($method, '/', [ |
29 | 50 | "Caller"=>"5557778889" |
30 | 51 | ]); |
|
33 | 54 | ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
34 | 55 | ->assertDontSee(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
35 | 56 | })->with(['GET', 'POST']); |
| 57 | + |
| 58 | +test('test the blocklist with whitespace in caller number', function ($method) { |
| 59 | + $caller = "+15557778888"; |
| 60 | + $settingsService = new SettingsService(); |
| 61 | + $settingsService->set("blocklist", $caller); |
| 62 | + app()->instance(SettingsService::class, $settingsService); |
| 63 | + $response = $this->call($method, '/', [ |
| 64 | + "Caller" => " 15557778888 " |
| 65 | + ]); |
| 66 | + $response |
| 67 | + ->assertStatus(200) |
| 68 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 69 | + ->assertSeeInOrderExact(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 70 | +})->with(['GET', 'POST']); |
| 71 | + |
| 72 | +test('test the blocklist with whitespace in blocklist entries', function ($method) { |
| 73 | + $caller = " +15557778888 , +15557778890 "; |
| 74 | + $settingsService = new SettingsService(); |
| 75 | + $settingsService->set("blocklist", $caller); |
| 76 | + app()->instance(SettingsService::class, $settingsService); |
| 77 | + $response = $this->call($method, '/', [ |
| 78 | + "Caller" => "+15557778890" |
| 79 | + ]); |
| 80 | + $response |
| 81 | + ->assertStatus(200) |
| 82 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 83 | + ->assertSeeInOrderExact(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 84 | +})->with(['GET', 'POST']); |
| 85 | + |
| 86 | +test('test the blocklist with missing plus sign in caller number', function ($method) { |
| 87 | + $caller = "+15557778888"; |
| 88 | + $settingsService = new SettingsService(); |
| 89 | + $settingsService->set("blocklist", $caller); |
| 90 | + app()->instance(SettingsService::class, $settingsService); |
| 91 | + $response = $this->call($method, '/', [ |
| 92 | + "Caller" => "15557778888" |
| 93 | + ]); |
| 94 | + $response |
| 95 | + ->assertStatus(200) |
| 96 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 97 | + ->assertSeeInOrderExact(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 98 | +})->with(['GET', 'POST']); |
| 99 | + |
| 100 | +test('test the blocklist with missing plus sign in blocklist entries', function ($method) { |
| 101 | + $caller = "15557778888,15557778890"; |
| 102 | + $settingsService = new SettingsService(); |
| 103 | + $settingsService->set("blocklist", $caller); |
| 104 | + app()->instance(SettingsService::class, $settingsService); |
| 105 | + $response = $this->call($method, '/', [ |
| 106 | + "Caller" => "+15557778890" |
| 107 | + ]); |
| 108 | + $response |
| 109 | + ->assertStatus(200) |
| 110 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 111 | + ->assertSeeInOrderExact(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 112 | +})->with(['GET', 'POST']); |
| 113 | + |
| 114 | +test('test the blocklist with empty blocklist', function ($method) { |
| 115 | + $settingsService = new SettingsService(); |
| 116 | + $settingsService->set("blocklist", ""); |
| 117 | + app()->instance(SettingsService::class, $settingsService); |
| 118 | + $response = $this->call($method, '/', [ |
| 119 | + "Caller" => "+15557778888" |
| 120 | + ]); |
| 121 | + $response |
| 122 | + ->assertStatus(200) |
| 123 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 124 | + ->assertDontSee(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 125 | +})->with(['GET', 'POST']); |
| 126 | + |
| 127 | +test('test the blocklist with missing Caller parameter', function ($method) { |
| 128 | + $caller = "+15557778888"; |
| 129 | + $settingsService = new SettingsService(); |
| 130 | + $settingsService->set("blocklist", $caller); |
| 131 | + app()->instance(SettingsService::class, $settingsService); |
| 132 | + $response = $this->call($method, '/', []); |
| 133 | + $response |
| 134 | + ->assertStatus(200) |
| 135 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 136 | + ->assertDontSee(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 137 | +})->with(['GET', 'POST']); |
| 138 | + |
| 139 | +test('test the blocklist with partial match', function ($method) { |
| 140 | + $caller = "+15557778888"; |
| 141 | + $settingsService = new SettingsService(); |
| 142 | + $settingsService->set("blocklist", $caller); |
| 143 | + app()->instance(SettingsService::class, $settingsService); |
| 144 | + $response = $this->call($method, '/', [ |
| 145 | + "Caller" => "+1555777888899" |
| 146 | + ]); |
| 147 | + $response |
| 148 | + ->assertStatus(200) |
| 149 | + ->assertHeader("Content-Type", "text/xml; charset=utf-8") |
| 150 | + ->assertDontSee(["<?xml version='1.0' encoding='UTF-8'?><Response><Reject/></Response>"], false); |
| 151 | +})->with(['GET', 'POST']); |
0 commit comments