@studyportals/cors 2.6.1 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/{bin/index.d.ts → index.d.ts} +2 -2
  2. package/{bin/index.js → index.js} +18 -18
  3. package/package.json +38 -38
  4. package/{bin/src → src}/domain/allowed-domain-reg-ex-list.d.ts +10 -10
  5. package/{bin/src → src}/domain/allowed-domain-reg-ex-list.js +28 -27
  6. package/{bin/src → src}/domain/allowed-explicit-domains-rules.d.ts +42 -42
  7. package/{bin/src → src}/domain/allowed-explicit-domains-rules.js +46 -42
  8. package/{bin/src → src}/domain/cors.d.ts +16 -16
  9. package/{bin/src → src}/domain/cors.js +37 -37
  10. package/{bin/src → src}/domain/enums/environment.d.ts +4 -4
  11. package/{bin/src → src}/domain/enums/environment.js +8 -8
  12. package/{bin/src → src}/domain/enums/index.d.ts +2 -2
  13. package/{bin/src → src}/domain/enums/index.js +18 -18
  14. package/{bin/src → src}/domain/enums/scope.d.ts +4 -4
  15. package/{bin/src → src}/domain/enums/scope.js +8 -8
  16. package/{bin/src → src}/domain/index.d.ts +3 -3
  17. package/{bin/src → src}/domain/index.js +19 -19
  18. package/{bin/src → src}/implementations/express-middleware.d.ts +5 -5
  19. package/{bin/src → src}/implementations/express-middleware.js +27 -27
  20. package/{bin/src → src}/implementations/index.d.ts +3 -3
  21. package/{bin/src → src}/implementations/index.js +19 -19
  22. package/{bin/src → src}/implementations/options.d.ts +8 -8
  23. package/{bin/src → src}/implementations/options.js +49 -49
  24. package/{bin/src → src}/implementations/s3-rules.d.ts +5 -5
  25. package/{bin/src → src}/implementations/s3-rules.js +12 -12
  26. package/.codeclimate.yml +0 -25
  27. package/.github/CODEOWNERS +0 -1
  28. package/.nycrc +0 -22
  29. package/.travis.yml +0 -18
  30. package/README.md +0 -110
  31. package/index.ts +0 -2
  32. package/src/domain/allowed-domain-reg-ex-list.ts +0 -26
  33. package/src/domain/allowed-explicit-domains-rules.ts +0 -56
  34. package/src/domain/cors.ts +0 -32
  35. package/src/domain/enums/environment.ts +0 -4
  36. package/src/domain/enums/index.ts +0 -2
  37. package/src/domain/enums/scope.ts +0 -4
  38. package/src/domain/index.ts +0 -3
  39. package/src/implementations/express-middleware.ts +0 -21
  40. package/src/implementations/index.ts +0 -3
  41. package/src/implementations/options.ts +0 -50
  42. package/src/implementations/s3-rules.ts +0 -12
  43. package/test/domain/cors.s3.test.ts +0 -92
  44. package/test/domain/cors.valid.domain.test.ts +0 -155
  45. package/test/mocha.opts +0 -3
  46. package/tsconfig.json +0 -38
  47. package/tslint.json +0 -132
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- import {CORS} from '../domain';
4
- import { Environment, Scope } from '../domain/enums';
5
-
6
- export class OptionsLambda {
7
- private cors: CORS;
8
-
9
- constructor(scope: Scope, environment: Environment = Environment.Production) {
10
- this.cors = new CORS(scope, environment);
11
- }
12
-
13
- getLowercasedHeaders(event: any): any {
14
- const headers = {};
15
-
16
- Object.keys(event.headers).forEach((key) => {
17
- headers[key.toLowerCase()] = event.headers[key];
18
- });
19
-
20
- return headers;
21
- }
22
-
23
- getOrigin(event: any): string {
24
- const headers = this.getLowercasedHeaders(event);
25
- return headers['origin'];
26
- }
27
-
28
- getHandler(): (event: any) => Promise<any> {
29
- return async (event) => {
30
-
31
- const origin = this.getOrigin(event);
32
- const headers = {
33
- 'Cache-Control': 'max-age=600, s-maxage=600, proxy-revalidate',
34
- };
35
-
36
- if (await this.cors.isValidDomain(origin)) {
37
- headers['Access-Control-Allow-Origin'] = origin;
38
- headers['Access-Control-Allow-Headers'] = 'authorization, x-api-key, content-type';
39
- headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PATCH, HEAD, PUT, OPTIONS';
40
- headers['Access-Control-Max-Age'] = '600';
41
- }
42
-
43
- return {
44
- statusCode: 200,
45
- headers,
46
- };
47
- };
48
- }
49
-
50
- }
@@ -1,12 +0,0 @@
1
- import { NextFunction, Request, RequestHandler, Response } from 'express';
2
- import { CORS } from '../domain';
3
- import { AllowedExplicitDomainsRulesType, CorsRule } from '../domain/allowed-explicit-domains-rules';
4
- import { Environment, Scope } from '../domain/enums';
5
-
6
- export class S3Rules {
7
-
8
- public static generate(scope: Scope, environment: Environment = Environment.Production): CorsRule[] {
9
- const cors = new CORS(scope, environment);
10
- return cors.getS3Rules();
11
- }
12
- }
@@ -1,92 +0,0 @@
1
- import { assert, expect } from "chai";
2
- import { suite, test } from "mocha-typescript";
3
- import * as Moq from "typemoq";
4
-
5
- import { CORS } from "../../src/domain";
6
- import { Environment } from "../../src/domain/enums/environment";
7
- import { Scope } from "../../src/domain/enums/scope";
8
-
9
- @suite()
10
- class CORSS3RulesTest {
11
- private testInstanceMock: Moq.IMock<CORS>;
12
-
13
- private get testInstance(): CORS {
14
- return this.testInstanceMock.object;
15
- }
16
-
17
- public before(): void {
18
-
19
- const cors = new CORS(Scope.Student, Environment.Production);
20
- this.testInstanceMock = Moq.Mock.ofInstance(cors);
21
- this.testInstanceMock.callBase = true;
22
- }
23
-
24
- @test
25
- public async getS3Rules_Should_Return_All_Required_Properties(): Promise<void> {
26
- // given
27
- const expectedProperties = ['allowedOrigins','allowedHeaders','allowedMethods','exposedHeaders','maxAge']
28
-
29
- // when
30
- const allDefaultRules = await this.testInstance.getS3Rules();
31
-
32
- //then
33
- expectedProperties.forEach((key) => {
34
- allDefaultRules.every( rule => expect(rule).to.have.property(key));
35
- });
36
-
37
- }
38
-
39
- @test
40
- public async getS3Rules_Should_Return_Correct_Default_Domains(): Promise<void> {
41
- // given
42
- const expectedDomains = ['*.mastersportal.com', '*.bachelorsportal.com', '*.phdportal.com'];
43
-
44
- // when
45
- const allDefaultRules = await this.testInstance.getS3Rules();
46
-
47
- // then
48
- allDefaultRules.some( rule => expectedDomains.every( domain => rule.allowedOrigins.includes(domain) ) )
49
- }
50
-
51
- @test
52
- public async getS3Rules_Should_Return_Correct_Allowed_Headers(): Promise<void> {
53
- // given
54
- const expectedHeaders = ['Authorization'];
55
-
56
- // when
57
- const allDefaultRules = await this.testInstance.getS3Rules();
58
-
59
- // then
60
- allDefaultRules.some( rule => expectedHeaders.every( header => !rule.allowedHeaders.includes(header) ) )
61
- }
62
-
63
- @test
64
- public async getS3Rules_Non_Production_Should_Not_Return_Production_Domains(): Promise<void> {
65
- // given
66
- const expectedDomains = ['*.mastersportal.fyi', '*.bachelorsportal.fyi', '*.phdportal.fyi'];
67
-
68
- // when
69
- const allDefaultRules = await this.testInstance.getS3Rules();
70
-
71
- // then
72
- allDefaultRules.some( rule => expectedDomains.every( domain => !rule.allowedOrigins.includes(domain) ) )
73
-
74
- }
75
-
76
- @test
77
- public async getS3Rules_Should_Return_Correct_Testing_Domains(): Promise<void> {
78
-
79
- const cors = new CORS(Scope.Student, Environment.Testing);
80
- this.testInstanceMock = Moq.Mock.ofInstance(cors);
81
- this.testInstanceMock.callBase = true;
82
-
83
- // given
84
- const expectedDomains = ['*'];
85
-
86
- // when
87
- const allDefaultRules = await this.testInstance.getS3Rules();
88
-
89
- // then
90
- allDefaultRules.some( rule => expectedDomains.every( domain => rule.allowedOrigins.includes(domain) ) )
91
- }
92
- }
@@ -1,155 +0,0 @@
1
- import { assert } from 'chai';
2
- import { suite, test } from 'mocha-typescript';
3
- import * as Moq from 'typemoq';
4
-
5
- import { CORS } from '../../src/domain';
6
- import { Environment } from '../../src/domain/enums/environment';
7
- import { Scope } from '../../src/domain/enums/scope';
8
-
9
- @suite()
10
- class CORSValidDomainTest {
11
- private testInstanceMock: Moq.IMock<CORS>;
12
-
13
- private get testInstance(): CORS {
14
- return this.testInstanceMock.object;
15
- }
16
-
17
- public before(): void {
18
-
19
- const cors = new CORS(Scope.Student, Environment.Production);
20
- this.testInstanceMock = Moq.Mock.ofInstance(cors);
21
- this.testInstanceMock.callBase = true;
22
- }
23
-
24
- @test
25
- public async isValidDomain_Should_Return_True_When_DomainIs_Mastersportal(): Promise<void> {
26
- // given
27
- const providedDomain = 'https://www.mastersportal.com';
28
-
29
- // when
30
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
31
-
32
- // then
33
- assert.isTrue(validDomain);
34
- }
35
-
36
- @test
37
- public async isValidDomain_Should_Return_True_When_DomainIs_Mastersportal_With_HTTP(): Promise<void> {
38
- // given
39
- const providedDomain = 'http://www.mastersportal.com';
40
-
41
- // when
42
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
43
-
44
- // then
45
- assert.isTrue(validDomain);
46
- }
47
-
48
- @test
49
- public async isValidDomain_Should_Return_True_When_DomainIs_Bachelorsportal(): Promise<void> {
50
- // given
51
- const providedDomain = 'https://www.bachelorsportal.com';
52
-
53
- // when
54
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
55
-
56
- // then
57
- assert.isTrue(validDomain);
58
- }
59
-
60
- @test
61
- public async isValidDomain_Should_Return_True_When_DomainIs_PhDportal(): Promise<void> {
62
- // given
63
- const providedDomain = 'https://www.phdportal.com';
64
-
65
- // when
66
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
67
-
68
- // then
69
- assert.isTrue(validDomain);
70
- }
71
-
72
- @test
73
- public async isValidDomain_Should_Return_True_When_DomainIs_PhDportalRC(): Promise<void> {
74
- // given
75
- const providedDomain = 'https://1554112850.rc.phdportal.fyi';
76
-
77
- // when
78
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
79
-
80
- // then
81
- assert.isTrue(validDomain);
82
- }
83
-
84
- @test
85
- public async isValidDomain_Should_Return_False_When_DomainIs_BabyShower(): Promise<void> {
86
- // given
87
- const providedDomain = 'https://www.babyshower.com';
88
-
89
- // when
90
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
91
-
92
- // then
93
- assert.isFalse(validDomain);
94
- }
95
-
96
- @test
97
- public async isValidDomain_Should_Return_False_When_DomainIs_Masterportal(): Promise<void> {
98
- // given
99
- const providedDomain = 'https://www.masterportal.com';
100
-
101
- // when
102
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
103
-
104
- // then
105
- assert.isFalse(validDomain);
106
- }
107
-
108
- @test
109
- public async isValidDomain_Should_Return_False_When_DomainIs_Mastersportal_With_SPDY(): Promise<void> {
110
- // given
111
- const providedDomain = 'spdy://www.mastersportal.com';
112
-
113
- // when
114
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
115
-
116
- // then
117
- assert.isFalse(validDomain);
118
- }
119
-
120
- @test
121
- public async isValidDomain_Should_Return_True_When_DomainIs_searchPageMicroFrontend(): Promise<void> {
122
- // given
123
- const providedDomain = 'https://search-page.prtl.co';
124
-
125
- // when
126
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
127
-
128
- // then
129
- assert.isTrue(validDomain);
130
- }
131
-
132
- @test
133
- public async isValidDomain_Should_Return_True_When_DomainIs_AdmissionTestPortalWithoutWWW(): Promise<void> {
134
- // given
135
- const providedDomain = 'https://admissiontestportal.com';
136
-
137
- // when
138
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
139
-
140
- // then
141
- assert.isTrue(validDomain);
142
- }
143
-
144
- @test
145
- public async isValidDomain_Should_Return_True_When_DomainIs_AdmissionTestPortalWithWWW(): Promise<void> {
146
- // given
147
- const providedDomain = 'https://www.admissiontestportal.com';
148
-
149
- // when
150
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
151
-
152
- // then
153
- assert.isTrue(validDomain);
154
- }
155
- }
package/test/mocha.opts DELETED
@@ -1,3 +0,0 @@
1
- --require ts-node/register
2
- --watch-extensions ts
3
- -c
package/tsconfig.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "bin",
4
- "declaration": true,
5
- "moduleResolution": "node",
6
- "alwaysStrict": true,
7
- "strictNullChecks": true,
8
- "allowJs": false,
9
- "allowUnreachableCode": false,
10
- "allowUnusedLabels": false,
11
- "noUnusedLocals": false,
12
- "noUnusedParameters": false,
13
- "noFallthroughCasesInSwitch": true,
14
- "noImplicitAny": false,
15
- "noImplicitReturns": true,
16
- "noImplicitThis": true,
17
- "target": "ES6",
18
- "module": "commonjs",
19
- "experimentalDecorators": true,
20
- "esModuleInterop": true,
21
- "lib": [
22
- "es2017",
23
- "dom",
24
- "es5",
25
- "es6"
26
- ],
27
- "types": [
28
- "node"
29
- ]
30
- },
31
- "typeRoots": [
32
- "node_modules/@types/"
33
- ],
34
- "exclude": [
35
- "node_modules",
36
- "bin"
37
- ]
38
- }
package/tslint.json DELETED
@@ -1,132 +0,0 @@
1
- {
2
- "extends": [
3
- "tslint:latest"
4
- ],
5
- "rules": {
6
- "ordered-imports": true,
7
- "arrow-return-shorthand": true,
8
- "callable-types": true,
9
- "class-name": true,
10
- "comment-format": [
11
- true,
12
- "check-space"
13
- ],
14
- "curly": true,
15
- "eofline": true,
16
- "forin": true,
17
- "import-spacing": false,
18
- "indent": [
19
- true,
20
- "tabs"
21
- ],
22
- "interface-over-type-literal": true,
23
- "label-position": true,
24
- "max-line-length": [
25
- true,
26
- 200
27
- ],
28
- "member-access": false,
29
- "member-ordering": [
30
- true,
31
- {
32
- "order": [
33
- "static-field",
34
- "instance-field",
35
- "instance-method",
36
- "static-method"
37
- ]
38
- }
39
- ],
40
- "no-arg": true,
41
- "no-console": [
42
- true,
43
- "debug",
44
- "info",
45
- "time",
46
- "timeEnd",
47
- "trace"
48
- ],
49
- "no-construct": true,
50
- "no-debugger": true,
51
- "no-duplicate-super": true,
52
- "no-empty": false,
53
- "no-empty-interface": true,
54
- "no-eval": true,
55
- "no-inferrable-types": [
56
- true,
57
- "ignore-params"
58
- ],
59
- "no-misused-new": true,
60
- "no-non-null-assertion": true,
61
- "no-shadowed-variable": true,
62
- "no-string-literal": false,
63
- "no-string-throw": true,
64
- "no-switch-case-fall-through": true,
65
- "no-trailing-whitespace": true,
66
- "no-unnecessary-initializer": true,
67
- "no-unused-expression": true,
68
- "no-use-before-declare": true,
69
- "no-var-keyword": true,
70
- "object-literal-sort-keys": false,
71
- "one-line": [
72
- true,
73
- "check-open-brace",
74
- "check-whitespace"
75
- ],
76
- "prefer-const": false,
77
- "radix": true,
78
- "quotemark": [
79
- true,
80
- "single"
81
- ],
82
- "semicolon": [
83
- true,
84
- "always"
85
- ],
86
- "triple-equals": [
87
- true,
88
- "allow-null-check"
89
- ],
90
- "typedef": [
91
- true,
92
- "call-signature",
93
- "parameter",
94
- "member-variable-declaration",
95
- "property-declaration"
96
- ],
97
- "typedef-whitespace": [
98
- true,
99
- {
100
- "call-signature": "nospace",
101
- "index-signature": "nospace",
102
- "parameter": "nospace",
103
- "property-declaration": "nospace",
104
- "variable-declaration": "nospace"
105
- }
106
- ],
107
- "no-implicit-dependencies": [
108
- false,
109
- [
110
- "mocha-typescript",
111
- "chai",
112
- "typemoq"
113
- ]
114
- ],
115
- "unified-signatures": true,
116
- "variable-name": false,
117
- "whitespace": [
118
- true,
119
- "check-branch",
120
- "check-decl",
121
- "check-operator",
122
- "check-separator",
123
- "check-type",
124
- "check-typecast"
125
- ]
126
- },
127
- "linterOptions": {
128
- "exclude": [
129
- "node_modules/**"
130
- ]
131
- }
132
- }