@studyportals/cors 2.4.0 → 2.5.1

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 +43 -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 -52
  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 -132
  45. package/test/mocha.opts +0 -3
  46. package/tsconfig.json +0 -38
  47. package/tslint.json +0 -132
@@ -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,132 +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
-
10
- @suite()
11
- class CORSValidDomainTest {
12
- private testInstanceMock: Moq.IMock<CORS>;
13
-
14
- private get testInstance(): CORS {
15
- return this.testInstanceMock.object;
16
- }
17
-
18
- public before(): void {
19
-
20
- const cors = new CORS(Scope.Student, Environment.Production);
21
- this.testInstanceMock = Moq.Mock.ofInstance(cors);
22
- this.testInstanceMock.callBase = true;
23
- }
24
-
25
- @test
26
- public async isValidDomain_Should_Return_True_When_DomainIs_Mastersportal(): Promise<void> {
27
- // given
28
- const providedDomain = 'https://www.mastersportal.com';
29
-
30
- // when
31
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
32
-
33
- // then
34
- assert.isTrue(validDomain);
35
- }
36
-
37
- @test
38
- public async isValidDomain_Should_Return_True_When_DomainIs_Mastersportal_With_HTTP(): Promise<void> {
39
- // given
40
- const providedDomain = 'http://www.mastersportal.com';
41
-
42
- // when
43
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
44
-
45
- // then
46
- assert.isTrue(validDomain);
47
- }
48
-
49
- @test
50
- public async isValidDomain_Should_Return_True_When_DomainIs_Bachelorsportal(): Promise<void> {
51
- // given
52
- const providedDomain = 'https://www.bachelorsportal.com';
53
-
54
- // when
55
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
56
-
57
- // then
58
- assert.isTrue(validDomain);
59
- }
60
-
61
- @test
62
- public async isValidDomain_Should_Return_True_When_DomainIs_PhDportal(): Promise<void> {
63
- // given
64
- const providedDomain = 'https://www.phdportal.com';
65
-
66
- // when
67
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
68
-
69
- // then
70
- assert.isTrue(validDomain);
71
- }
72
-
73
- @test
74
- public async isValidDomain_Should_Return_True_When_DomainIs_PhDportalRC(): Promise<void> {
75
- // given
76
- const providedDomain = 'https://1554112850.rc.phdportal.fyi';
77
-
78
- // when
79
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
80
-
81
- // then
82
- assert.isTrue(validDomain);
83
- }
84
-
85
- @test
86
- public async isValidDomain_Should_Return_False_When_DomainIs_BabyShower(): Promise<void> {
87
- // given
88
- const providedDomain = 'https://www.babyshower.com';
89
-
90
- // when
91
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
92
-
93
- // then
94
- assert.isFalse(validDomain);
95
- }
96
-
97
- @test
98
- public async isValidDomain_Should_Return_False_When_DomainIs_Masterportal(): Promise<void> {
99
- // given
100
- const providedDomain = 'https://www.masterportal.com';
101
-
102
- // when
103
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
104
-
105
- // then
106
- assert.isFalse(validDomain);
107
- }
108
-
109
- @test
110
- public async isValidDomain_Should_Return_False_When_DomainIs_Mastersportal_With_SPDY(): Promise<void> {
111
- // given
112
- const providedDomain = 'spdy://www.mastersportal.com';
113
-
114
- // when
115
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
116
-
117
- // then
118
- assert.isFalse(validDomain);
119
- }
120
-
121
- @test
122
- public async isValidDomain_Should_Return_True_When_DomainIs_searchPageMicroFrontend(): Promise<void> {
123
- // given
124
- const providedDomain = 'https://search-page.prtl.co';
125
-
126
- // when
127
- const validDomain = await this.testInstance.isValidDomain(providedDomain);
128
-
129
- // then
130
- assert.isTrue(validDomain);
131
- }
132
- }
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
- }