-
Notifications
You must be signed in to change notification settings - Fork 0
Add webhook endpoint for gate certification intake #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
40f9de6
Add webhook endpoint for gate certification intake
jordanpartridge 2a5176c
Enable RefreshDatabase globally for all feature tests
jordanpartridge f428519
Simplify welcome view for API-focused project
jordanpartridge 41b9f00
Add .env.testing with valid APP_KEY for CI
jordanpartridge 9801ff0
Remove unused User model for 100% coverage
jordanpartridge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| APP_NAME="Synapse Sentinel Core" | ||
| APP_ENV=testing | ||
| APP_KEY=base64:uu9NaQgjKWHuLvyg3EZvLNYjVgrkunyitUMq88LDf4c= | ||
| APP_DEBUG=true | ||
| APP_URL=http://localhost | ||
|
|
||
| DB_CONNECTION=sqlite | ||
| DB_DATABASE=:memory: | ||
|
|
||
| CACHE_STORE=array | ||
| QUEUE_CONNECTION=sync | ||
| SESSION_DRIVER=array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Events; | ||
|
|
||
| use Thunk\Verbs\Event; | ||
|
|
||
| class CertificationCompleted extends Event | ||
| { | ||
| public function __construct( | ||
| public string $repository, | ||
| public string $sha, | ||
| public string $verdict, | ||
| public ?string $reason = null, | ||
| public ?array $checks = null, | ||
| public ?string $triggeredBy = null, | ||
| public ?int $prNumber = null, | ||
| ) {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Events\CertificationCompleted; | ||
| use App\Http\Requests\GateWebhookRequest; | ||
| use Illuminate\Http\JsonResponse; | ||
|
|
||
| class WebhookController extends Controller | ||
| { | ||
| public function gate(GateWebhookRequest $request): JsonResponse | ||
| { | ||
| CertificationCompleted::fire( | ||
| repository: $request->validated('repository'), | ||
| sha: $request->validated('sha'), | ||
| verdict: $request->validated('verdict'), | ||
| reason: $request->validated('reason'), | ||
| checks: $request->validated('checks'), | ||
| triggeredBy: $request->validated('triggered_by'), | ||
| prNumber: $request->validated('pr_number'), | ||
| ); | ||
|
|
||
| return response()->json(['status' => 'accepted']); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Requests; | ||
|
|
||
| use Illuminate\Foundation\Http\FormRequest; | ||
| use Illuminate\Validation\Rule; | ||
|
|
||
| class GateWebhookRequest extends FormRequest | ||
| { | ||
| public function authorize(): bool | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, mixed> | ||
| */ | ||
| public function rules(): array | ||
| { | ||
| return [ | ||
| 'repository' => ['required', 'string'], | ||
| 'sha' => ['required', 'string'], | ||
| 'verdict' => ['required', Rule::in(['approved', 'rejected', 'escalate'])], | ||
| 'reason' => ['nullable', 'string'], | ||
| 'checks' => ['nullable', 'array'], | ||
| 'triggered_by' => ['nullable', 'string'], | ||
| 'pr_number' => ['nullable', 'integer'], | ||
| ]; | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
database/migrations/0001_01_01_000000_create_users_table.php
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use App\Http\Controllers\WebhookController; | ||
| use Illuminate\Support\Facades\Route; | ||
|
|
||
| Route::post('/webhooks/gate', [WebhookController::class, 'gate']) | ||
| ->name('webhooks.gate'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| <?php | ||
|
|
||
| test('the application returns a successful response', function () { | ||
| $response = $this->get('/'); | ||
| declare(strict_types=1); | ||
|
|
||
| $response->assertStatus(200); | ||
| describe('Application', function () { | ||
| it('returns a successful response for the homepage', function () { | ||
| $response = $this->get('/'); | ||
|
|
||
| $response->assertOk(); | ||
| }); | ||
|
|
||
| it('has a health check endpoint', function () { | ||
| $response = $this->get('/up'); | ||
|
|
||
| $response->assertOk(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| describe('POST /api/webhooks/gate', function () { | ||
| it('accepts valid gate certification payload', function () { | ||
| $payload = [ | ||
| 'repository' => 'conduit-ui/pr', | ||
| 'sha' => 'abc123def456', | ||
| 'verdict' => 'approved', | ||
| 'reason' => 'All checks passed', | ||
| 'checks' => [ | ||
| 'tests' => ['status' => 'pass', 'coverage' => 100], | ||
| 'security' => ['status' => 'pass'], | ||
| 'syntax' => ['status' => 'pass'], | ||
| ], | ||
| 'triggered_by' => 'pull_request', | ||
| 'pr_number' => 42, | ||
| ]; | ||
|
|
||
| $response = $this->postJson('/api/webhooks/gate', $payload); | ||
|
|
||
| $response->assertSuccessful(); | ||
| $response->assertJson(['status' => 'accepted']); | ||
| }); | ||
|
|
||
| it('rejects payload missing required repository field', function () { | ||
| $payload = [ | ||
| 'sha' => 'abc123', | ||
| 'verdict' => 'approved', | ||
| ]; | ||
|
|
||
| $response = $this->postJson('/api/webhooks/gate', $payload); | ||
|
|
||
| $response->assertUnprocessable(); | ||
| $response->assertJsonValidationErrors(['repository']); | ||
| }); | ||
|
|
||
| it('rejects payload with invalid verdict value', function () { | ||
| $payload = [ | ||
| 'repository' => 'conduit-ui/pr', | ||
| 'sha' => 'abc123', | ||
| 'verdict' => 'invalid_verdict', | ||
| ]; | ||
|
|
||
| $response = $this->postJson('/api/webhooks/gate', $payload); | ||
|
|
||
| $response->assertUnprocessable(); | ||
| $response->assertJsonValidationErrors(['verdict']); | ||
| }); | ||
|
|
||
| it('stores certification event via Laravel Verbs', function () { | ||
| $payload = [ | ||
| 'repository' => 'conduit-ui/pr', | ||
| 'sha' => 'abc123def456', | ||
| 'verdict' => 'approved', | ||
| 'reason' => 'All checks passed', | ||
| 'checks' => [ | ||
| 'tests' => ['status' => 'pass', 'coverage' => 100], | ||
| ], | ||
| 'triggered_by' => 'push', | ||
| ]; | ||
|
|
||
| $response = $this->postJson('/api/webhooks/gate', $payload); | ||
|
|
||
| $response->assertSuccessful(); | ||
|
|
||
| $this->assertDatabaseHas('verb_events', [ | ||
| 'type' => 'App\Events\CertificationCompleted', | ||
| ]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| <?php | ||
|
|
||
| test('that true is true', function () { | ||
| expect(true)->toBeTrue(); | ||
| declare(strict_types=1); | ||
|
|
||
| describe('Unit', function () { | ||
| it('confirms basic assertions work', function () { | ||
| expect(true)->toBeTrue(); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 107
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 1086
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 374
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 151
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 221
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 171
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 314
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 141
🏁 Script executed:
# Read the WebhookController head -100 app/Http/Controllers/WebhookController.phpRepository: synapse-sentinel/core
Length of output: 859
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 2335
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 133
🏁 Script executed:
Repository: synapse-sentinel/core
Length of output: 124
Add authentication to the webhook endpoint; currently any caller can submit certification verdicts
The
authorize()method returnstrueunconditionally, the route has no middleware or auth guard, and no signature/HMAC validation exists anywhere in the codebase. This means any caller with network access can submit "approved" verdicts for any repository and commit, which is a critical security risk if this endpoint drives production gating decisions.Implement one of:
X-Hub-SignatureHMAC against a shared secret in middleware before the route is reached).🤖 Prompt for AI Agents