This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
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.
- Loading branch information
Showing
11 changed files
with
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @ts-ignore | ||
import { Event } from '@appland/models'; | ||
import Assertion from '../assertion'; | ||
import { contentType } from './util'; | ||
|
||
const isRedirect = (status: number) => | ||
[301, 302, 303, 307, 308].includes(status); | ||
const isNoContent = (status: number) => status != 204; | ||
|
||
export default function () { | ||
return Assertion.assert( | ||
'http_server_request', | ||
(e: Event) => contentType(e) !== undefined, | ||
(assertion: Assertion): void => { | ||
assertion.where = (e: Event) => | ||
e.httpServerResponse !== undefined && !isRedirect(e.httpServerResponse!.status_code) && !isNoContent(e.httpServerResponse!.status_code); | ||
assertion.description = `HTTP server request must have a Content-Type header`; | ||
} | ||
); | ||
} |
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,40 @@ | ||
// @ts-ignore | ||
import { Event, EventNavigator } from '@appland/models'; | ||
import Assertion from '../assertion'; | ||
import { contentType, isFalsey } from './util'; | ||
|
||
function isPublic(event: Event): boolean { | ||
return event.labels.has('public'); | ||
} | ||
|
||
function providesAuthentication(event: Event) { | ||
return ( | ||
event.labels.has('security.authentication') && !isFalsey(event.returnValue) | ||
); | ||
} | ||
|
||
export default function ( | ||
routes: RegExp[] = [/.*/], | ||
contentTypes: RegExp[] = [/.*/] | ||
) { | ||
return Assertion.assert( | ||
'http_server_request', | ||
(event: Event) => | ||
new EventNavigator(event) | ||
.descendants((e: Event) => isPublic(e) || providesAuthentication(e)) | ||
.next()?.value, | ||
(assertion: Assertion): void => { | ||
assertion.where = (e: Event) => { | ||
return ( | ||
e.route !== undefined && | ||
e.httpServerResponse !== undefined && | ||
e.httpServerResponse!.status_code < 300 && | ||
contentType(e) !== undefined && | ||
routes.some((pattern) => pattern.test(e.route!)) && | ||
contentTypes.some((pattern) => pattern.test(contentType(e)!)) | ||
); | ||
}; | ||
assertion.description = `HTTP server request must be authenticated`; | ||
} | ||
); | ||
} |
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,23 @@ | ||
// @ts-ignore | ||
import { Event } from '@appland/models'; | ||
import Assertion from '../assertion'; | ||
|
||
const Whitelist = [/BEGIN/, /COMMIT/, /ROLLBACK/, /RELEASE/, /SAVEPOINT/]; | ||
|
||
export default function (parentPackages: string[], whitelist: RegExp[] = []) { | ||
return Assertion.assert( | ||
'event', | ||
(e: Event) => parentPackages.includes(e.parent!.codeObject.packageOf), | ||
(assertion: Assertion): void => { | ||
assertion.where = (e: Event) => | ||
e.sqlQuery !== undefined && | ||
e.parent !== undefined && | ||
!whitelist | ||
.concat(Whitelist) | ||
.some((pattern) => pattern.test(e.sqlQuery!)); | ||
assertion.description = `Query must be invoked from one of (${parentPackages.join( | ||
',' | ||
)})`; | ||
} | ||
); | ||
} |
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,31 @@ | ||
// @ts-ignore | ||
import { Event } from '@appland/models'; | ||
|
||
/* | ||
const responseHeaders = (event: Event): any => { | ||
return event.httpServerResponse?.headers || event.httpClientResponse?.headers || {}; | ||
}; | ||
*/ | ||
|
||
// TODO: Why is mime_type still defined on httpServerResponse? It should be "headers". | ||
const contentType = (event: Event): string | undefined => event.httpServerResponse?.mime_type; | ||
// responseHeaders(event)['Content-Type'] || | ||
|
||
function isFalsey(valueObj: any): boolean { | ||
if (!valueObj) { | ||
return true; | ||
} | ||
if (valueObj.class === 'FalseClass') { | ||
return true; | ||
} | ||
if (valueObj.class === 'Array' && valueObj.value === '[]') { | ||
return true; | ||
} | ||
if (valueObj.value === '') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export { contentType, isFalsey }; |
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
// @ts-ignore | ||
import { Event } from '@appland/models'; | ||
import Strategy from './strategy'; | ||
import { Scope } from '../types'; | ||
|
||
export default class EventStrategy extends Strategy { | ||
protected scope: Scope = 'event'; | ||
|
||
protected isEventApplicable(event: Event): boolean { | ||
return true; | ||
} | ||
} |
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