-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
test-origin.ts
64 lines (58 loc) · 1.78 KB
/
test-origin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Construct } from 'constructs';
import {
CfnDistribution,
IOrigin,
OriginBase,
OriginBindConfig,
OriginBindOptions,
OriginProps,
OriginProtocolPolicy,
} from '../lib';
/** Used for testing common Origin functionality */
export class TestOrigin extends OriginBase {
constructor(domainName: string, props: OriginProps = {}) {
super(domainName, props);
}
protected renderCustomOriginConfig():
| CfnDistribution.CustomOriginConfigProperty
| undefined {
return { originProtocolPolicy: OriginProtocolPolicy.HTTPS_ONLY };
}
}
export class TestOriginGroup implements IOrigin {
constructor(
private readonly primaryDomainName: string,
private readonly secondaryDomainName: string,
) {}
/* eslint-disable @cdklabs/no-core-construct */
public bind(scope: Construct, options: OriginBindOptions): OriginBindConfig {
const primaryOrigin = new TestOrigin(this.primaryDomainName);
const secondaryOrigin = new TestOrigin(this.secondaryDomainName);
const primaryOriginConfig = primaryOrigin.bind(scope, options);
return {
originProperty: primaryOriginConfig.originProperty,
failoverConfig: {
failoverOrigin: secondaryOrigin,
},
};
}
}
export function defaultOrigin(domainName?: string, originId?: string): IOrigin {
return new TestOrigin(domainName ?? 'www.example.com', {
originId,
});
}
export function defaultOriginGroup(): IOrigin {
return new TestOriginGroup('www.example.com', 'foo.example.com');
}
export function defaultOriginWithOriginAccessControl(
domainName?: string,
originId?: string,
originAccessControlId?: string,
): IOrigin {
return new TestOrigin(domainName ?? 'www.example.com', {
originId,
originAccessControlId:
originAccessControlId ?? 'test-origin-access-control-id',
});
}