@@ -41,6 +41,9 @@ describe('OCI region registry', () => {
4141 expect ( regionalOciHostname ( 'objectstorage' , region , 'regional' ) ) . toBe (
4242 `objectstorage.${ id } .${ region . realm . domain } `
4343 )
44+ expect ( regionalOciHostname ( 'functions' , region , 'region-first-oci' ) ) . toBe (
45+ `${ id } .functions.oci.${ region . realm . domain } `
46+ )
4447 }
4548 } )
4649
@@ -60,6 +63,79 @@ describe('OCI region registry', () => {
6063
6164describe ( 'OCI endpoint policies' , ( ) => {
6265 const region = getOciRegion ( 'us-ashburn-1' )
66+ const functionsManagementPolicy = createOciStaticEndpointPolicy ( {
67+ serviceId : OCI_SERVICE_ID ,
68+ serviceName : 'functions' ,
69+ hostnameTemplate : 'regional-oci' ,
70+ } )
71+ const functionsInvocationPolicy = createOciDiscoveredEndpointPolicy ( {
72+ serviceId : OCI_SERVICE_ID ,
73+ serviceName : 'functions' ,
74+ hostnameTemplate : 'region-first-oci' ,
75+ responsePolicy : functionsManagementPolicy ,
76+ source : { kind : 'json' , path : [ 'invokeEndpoint' ] } ,
77+ } )
78+
79+ it . each ( [ 'us-ashburn-1' , 'us-gov-ashburn-1' ] ) (
80+ 'supports region-first policies and authenticated Functions discovery in %s' ,
81+ ( regionId ) => {
82+ const selectedRegion = getOciRegion ( regionId )
83+ const hostname = `${ regionId } .functions.oci.${ selectedRegion . realm . domain } `
84+ expect (
85+ resolveStaticOciEndpoint (
86+ createOciStaticEndpointPolicy ( {
87+ serviceId : OCI_SERVICE_ID ,
88+ serviceName : 'functions' ,
89+ hostnameTemplate : 'region-first-oci' ,
90+ } ) ,
91+ selectedRegion
92+ ) . origin
93+ ) . toBe ( `https://${ hostname } ` )
94+ expect (
95+ resolveDiscoveredOciEndpoint (
96+ functionsInvocationPolicy ,
97+ selectedRegion ,
98+ `https://resource.${ hostname } `
99+ )
100+ ) . toMatchObject ( {
101+ origin : `https://resource.${ hostname } ` ,
102+ serviceId : OCI_SERVICE_ID ,
103+ provenance : 'authenticated-discovery' ,
104+ } )
105+ expect ( Object . isFrozen ( functionsInvocationPolicy ) ) . toBe ( true )
106+ expect ( functionsInvocationPolicy . hostnameTemplate ) . toBe ( 'region-first-oci' )
107+ expect ( functionsInvocationPolicy . allowRegionalHost ) . toBe ( false )
108+ expect (
109+ resolveDiscoveredOciEndpoint (
110+ createOciDiscoveredEndpointPolicy ( {
111+ ...functionsInvocationPolicy ,
112+ allowRegionalHost : true ,
113+ } ) ,
114+ selectedRegion ,
115+ `https://${ hostname } `
116+ ) . hostname
117+ ) . toBe ( hostname )
118+ }
119+ )
120+
121+ it . each ( [
122+ 'https://resource.functions.us-ashburn-1.oci.oraclecloud.com' ,
123+ 'https://resource.eu-frankfurt-1.functions.oci.oraclecloud.com' ,
124+ 'https://resource.us-ashburn-1.functions.oci.oraclegovcloud.com' ,
125+ 'https://resource.us-ashburn-1.database.oci.oraclecloud.com' ,
126+ 'https://resource.us-ashburn-1.functions.oci.oraclecloud.com.attacker.example' ,
127+ 'https://resourceus-ashburn-1.functions.oci.oraclecloud.com' ,
128+ 'https://us-ashburn-1.functions.oci.oraclecloud.com' ,
129+ 'http://resource.us-ashburn-1.functions.oci.oraclecloud.com' ,
130+ 'https://resource.us-ashburn-1.functions.oci.oraclecloud.com:8443' ,
131+ 'https://user:password@resource.us-ashburn-1.functions.oci.oraclecloud.com' ,
132+ 'https://resource.us-ashburn-1.functions.oci.oraclecloud.com/path' ,
133+ 'https://resource.us-ashburn-1.functions.oci.oraclecloud.com?query=1' ,
134+ 'https://resource.us-ashburn-1.functions.oci.oraclecloud.com#fragment' ,
135+ 'https://127.0.0.1' ,
136+ ] ) ( 'rejects invalid Functions invocation origins: %s' , ( origin ) => {
137+ expect ( ( ) => resolveDiscoveredOciEndpoint ( functionsInvocationPolicy , region , origin ) ) . toThrow ( )
138+ } )
63139
64140 it ( 'freezes declarative policies and derives exact static origins' , ( ) => {
65141 expect ( Object . isFrozen ( staticPolicy ) ) . toBe ( true )
0 commit comments