-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redirect to e403 page when webhook rejects the request
re #4
- Loading branch information
1 parent
f59a5d3
commit b9b4b0c
Showing
8 changed files
with
796 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,59 @@ | ||
import { suite, test } from "@testdeck/mocha"; | ||
import { BaseSuite } from "./Base.suite"; | ||
import { getConfig } from "../src/config/getConfig"; | ||
import { strictEqual } from "assert"; | ||
|
||
const OpenApiMocker = require('open-api-mocker'); | ||
|
||
@suite() | ||
class PublicMappingSuite extends BaseSuite { | ||
private mockServer: any; | ||
|
||
private static mockPort = 7777; | ||
private static rejectURL = `http://localhost:${PublicMappingSuite.mockPort}/reject`; | ||
|
||
public async before() { | ||
await this.initMockServer(); | ||
await super.before(); | ||
} | ||
|
||
public async after() { | ||
this.mockServer?.shutdown(); | ||
this.mockServer = null; | ||
await super.after(); | ||
} | ||
|
||
/** | ||
* Init mock server | ||
*/ | ||
private async initMockServer(): Promise<void> { | ||
const mocker = this.mockServer = new OpenApiMocker({ | ||
port: PublicMappingSuite.mockPort, | ||
schema: 'test/assets/webhook/mock.yml', | ||
}); | ||
|
||
await mocker.validate(); | ||
await mocker.mock(); | ||
} | ||
|
||
@test() | ||
async rejectLogin(): Promise<void> { | ||
await this.reloadPrxiWith({ | ||
webhook: { | ||
login: PublicMappingSuite.rejectURL, | ||
} | ||
}); | ||
|
||
await this.withNewPage(getConfig().hostURL + '/pages/test', async (page) => { | ||
await this.loginOnKeycloak(page); | ||
const text = await this.getTextFromPage(page); | ||
|
||
const json = JSON.parse(text); | ||
// validate query to be in place | ||
strictEqual( | ||
json.http.originalUrl, | ||
new URL(getConfig().redirect.pageRequest.e403).pathname | ||
); | ||
}); | ||
} | ||
} |
This file contains 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 @@ | ||
openapi: '3.0.2' | ||
|
||
info: | ||
title: Mock WebHook Reject | ||
version: '1.0' | ||
|
||
paths: | ||
/reject: | ||
post: | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
reject: | ||
type: boolean | ||
x-faker: 'boolean(1)' |
Oops, something went wrong.