Rename package to mattitja/laravel-plausible-proxy
dependabot-auto-merge / dependabot (pull_request_target) Skipped
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 2m32s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 34s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
dependabot-auto-merge / dependabot (pull_request_target) Skipped
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 2m32s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 34s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
- Rename Composer package to mattitja/laravel-plausible-proxy and namespace to Mattitja\LaravelPlausibleProxy - Point homepage and links to git.mattitja.se - Forward only User-Agent and visitor IP (X-Forwarded-For) to Plausible instead of all request headers - Forward all event fields and return Plausible's upstream response - Accept props as array or JSON string - Drop Laravel 10, upgrade Larastan to 3 and PHPStan plugins to 2 - Remove broken facade alias and dead autoload paths - Clean up README, issue template and remove invalid FUNDING.yml
This commit is contained in:
16 files changed
+141
-112
No files matched your search
@@ -49,35 +49,69 @@ it('rejects invalid event data', function () {
|
||||
->assertJsonValidationErrors(['u' => 'The u field must be a valid URL.']);
|
||||
});
|
||||
|
||||
it('accepts valid event data and forwards headers', function () {
|
||||
it('forwards only user agent and client ip to plausible', function () {
|
||||
config()->set('plausible-proxy.domain', 'https://plausible.io');
|
||||
|
||||
Http::fake([
|
||||
'https://plausible.io/api/event' => function ($request) {
|
||||
return Http::response(['status' => 'queued'], 200);
|
||||
},
|
||||
'https://plausible.io/api/event' => Http::response('ok', 202),
|
||||
]);
|
||||
|
||||
$headers = [
|
||||
'User-Agent' => 'TestAgent',
|
||||
'Accept' => 'application/json',
|
||||
];
|
||||
$response = $this->withServerVariables(['REMOTE_ADDR' => '203.0.113.7'])
|
||||
->postJson('/api/event', [
|
||||
'n' => 'pageview',
|
||||
'u' => 'https://example.com/page',
|
||||
'd' => 'example.com',
|
||||
], [
|
||||
'User-Agent' => 'TestAgent',
|
||||
'Cookie' => 'laravel_session=secret',
|
||||
'Authorization' => 'Bearer secret',
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/api/event', [
|
||||
'n' => 'pageview',
|
||||
'u' => 'https://example.com/page',
|
||||
'd' => 'example.com',
|
||||
], $headers);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['status' => 'queued']);
|
||||
$response->assertStatus(202);
|
||||
expect($response->getContent())->toBe('ok');
|
||||
|
||||
Http::assertSentCount(1);
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return $request->url() === 'https://plausible.io/api/event'
|
||||
&& isset($request['n']) && $request['n'] === 'pageview'
|
||||
&& isset($request['u']) && $request['u'] === 'https://example.com/page'
|
||||
&& isset($request['d']) && $request['d'] === 'example.com';
|
||||
&& $request->header('User-Agent') === ['TestAgent']
|
||||
&& $request->header('X-Forwarded-For') === ['203.0.113.7']
|
||||
&& ! $request->hasHeader('Cookie')
|
||||
&& ! $request->hasHeader('Authorization')
|
||||
&& $request['n'] === 'pageview'
|
||||
&& $request['u'] === 'https://example.com/page'
|
||||
&& $request['d'] === 'example.com';
|
||||
});
|
||||
});
|
||||
|
||||
it('forwards additional plausible fields', function () {
|
||||
config()->set('plausible-proxy.domain', 'https://plausible.io');
|
||||
|
||||
Http::fake([
|
||||
'https://plausible.io/api/event' => Http::response('ok', 202),
|
||||
]);
|
||||
|
||||
$this->postJson('/api/event', [
|
||||
'n' => 'Purchase',
|
||||
'u' => 'https://example.com/checkout',
|
||||
'd' => 'example.com',
|
||||
'i' => false,
|
||||
'p' => '{"plan":"pro"}',
|
||||
'$' => ['amount' => '9.99', 'currency' => 'EUR'],
|
||||
])->assertStatus(202);
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return $request['i'] === false
|
||||
&& $request['p'] === '{"plan":"pro"}'
|
||||
&& $request['$'] === ['amount' => '9.99', 'currency' => 'EUR'];
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects invalid props', function () {
|
||||
$this->postJson('/api/event', [
|
||||
'n' => 'pageview',
|
||||
'u' => 'https://example.com/page',
|
||||
'd' => 'example.com',
|
||||
'p' => 'not-json',
|
||||
])->assertStatus(422)->assertJsonValidationErrors(['p']);
|
||||
});
|
||||
Reference in new issue
Block a user