Compare commits
7 commits
37fb52ba90
...
bc67ddc40c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc67ddc40c | ||
|
|
c3a4437a8f | ||
|
|
c2e2362abc | ||
|
|
fdaf60da7c | ||
|
|
3b4aa40eb0 | ||
|
|
f1e60bac53 | ||
|
|
3b45835909 |
2 changed files with 0 additions and 97 deletions
|
|
@ -6,7 +6,6 @@ on:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- "*.md"
|
- "*.md"
|
||||||
- ".github/**"
|
- ".github/**"
|
||||||
- "templates/**"
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: forgejo.mapledeploy.ca
|
REGISTRY: forgejo.mapledeploy.ca
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
Http::fake([
|
|
||||||
'discord.com/*' => Http::response([], 204),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects feedback with missing content', function () {
|
|
||||||
$response = $this->postJson('/api/feedback', []);
|
|
||||||
|
|
||||||
$response->assertStatus(422)
|
|
||||||
->assertJsonValidationErrors('content');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects feedback with content too short', function () {
|
|
||||||
$response = $this->postJson('/api/feedback', ['content' => 'short']);
|
|
||||||
|
|
||||||
$response->assertStatus(422)
|
|
||||||
->assertJsonValidationErrors('content');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects feedback with content too long', function () {
|
|
||||||
$response = $this->postJson('/api/feedback', ['content' => str_repeat('a', 2001)]);
|
|
||||||
|
|
||||||
$response->assertStatus(422)
|
|
||||||
->assertJsonValidationErrors('content');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects feedback with non-string content', function () {
|
|
||||||
$response = $this->postJson('/api/feedback', ['content' => ['array', 'value']]);
|
|
||||||
|
|
||||||
$response->assertStatus(422)
|
|
||||||
->assertJsonValidationErrors('content');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('accepts valid feedback and forwards to discord with mentions disabled', function () {
|
|
||||||
config()->set('constants.webhooks.feedback_discord_webhook', 'https://discord.com/api/webhooks/test');
|
|
||||||
|
|
||||||
$response = $this->postJson('/api/feedback', [
|
|
||||||
'content' => 'This is a valid feedback message for testing purposes.',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(200)
|
|
||||||
->assertJson(['message' => 'Feedback sent.']);
|
|
||||||
|
|
||||||
Http::assertSent(function ($request) {
|
|
||||||
return $request->url() === 'https://discord.com/api/webhooks/test'
|
|
||||||
&& $request['content'] === 'This is a valid feedback message for testing purposes.'
|
|
||||||
&& $request['allowed_mentions'] === ['parse' => []];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not forward to discord when webhook url is not configured', function () {
|
|
||||||
config()->set('constants.webhooks.feedback_discord_webhook', null);
|
|
||||||
|
|
||||||
$response = $this->postJson('/api/feedback', [
|
|
||||||
'content' => 'This is a valid feedback message for testing purposes.',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
|
|
||||||
Http::assertNothingSent();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('throttles feedback endpoint after 3 requests per minute', function () {
|
|
||||||
config()->set('constants.webhooks.feedback_discord_webhook', null);
|
|
||||||
|
|
||||||
for ($i = 0; $i < 3; $i++) {
|
|
||||||
$response = $this->postJson('/api/feedback', [
|
|
||||||
'content' => "Valid feedback message number {$i} for testing.",
|
|
||||||
]);
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $this->postJson('/api/feedback', [
|
|
||||||
'content' => 'This fourth request should be throttled.',
|
|
||||||
]);
|
|
||||||
$response->assertStatus(429);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('disables discord mention parsing regardless of content', function () {
|
|
||||||
config()->set('constants.webhooks.feedback_discord_webhook', 'https://discord.com/api/webhooks/test');
|
|
||||||
|
|
||||||
$response = $this->postJson('/api/feedback', [
|
|
||||||
'content' => 'User feedback includes an @everyone style phrase and a link https://example.com for reference.',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
|
|
||||||
Http::assertSent(function ($request) {
|
|
||||||
return $request['allowed_mentions'] === ['parse' => []];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
Reference in a new issue