diff --git a/services/src/modules/resource-repository/types.ts b/services/src/modules/resource-repository/types.ts index 63e4ff8f..eb0f2dd0 100644 --- a/services/src/modules/resource-repository/types.ts +++ b/services/src/modules/resource-repository/types.ts @@ -3,7 +3,8 @@ export interface ResourceGroup { upstreams: Upstream[]; upstreamClientCredentials: UpstreamClientCredentials[]; policies: Policy[]; - policyAttachments?: PolicyAttachments; + // policyAttachments are compiled from the Rego code in opa policies, they are not directly modified by users + policyAttachments: PolicyAttachments; } export interface Resource { diff --git a/services/src/tests/integration/registry/create-resources.spec.ts b/services/src/tests/integration/registry/create-resources.spec.ts index 6fbb64c8..a92bd13f 100644 --- a/services/src/tests/integration/registry/create-resources.spec.ts +++ b/services/src/tests/integration/registry/create-resources.spec.ts @@ -72,7 +72,6 @@ const baseResourceGroup = { upstreams: [], upstreamClientCredentials: [], policies: [], - policyAttachments: {}, }; describe('Create resource', () => { @@ -102,7 +101,7 @@ describe('Create resource', () => { expect(response.errors).toBeUndefined(); expect(response.data).toEqual({updateSchemas: {success: true}}); - expect(bucketContents.current).toEqual({...baseResourceGroup, schemas: [schema]}); + expect(bucketContents.current).toMatchObject({...baseResourceGroup, schemas: [schema]}); }); it('Upstream', async () => { @@ -121,7 +120,7 @@ describe('Create resource', () => { expect(response.errors).toBeUndefined(); expect(response.data).toEqual({updateUpstreams: {success: true}}); - expect(bucketContents.current).toEqual({...baseResourceGroup, upstreams: [upstream]}); + expect(bucketContents.current).toMatchObject({...baseResourceGroup, upstreams: [upstream]}); }); it('UpstreamClientCredentials', async () => { @@ -140,7 +139,7 @@ describe('Create resource', () => { expect(response.errors).toBeUndefined(); expect(response.data).toEqual({updateUpstreamClientCredentials: {success: true}}); - expect(bucketContents.current).toEqual({ + expect(bucketContents.current).toMatchObject({ ...baseResourceGroup, upstreamClientCredentials: [upstreamClientCredentials], }); @@ -164,7 +163,7 @@ describe('Create resource', () => { expect(response.errors).toBeUndefined(); expect(response.data).toEqual({updatePolicies: {success: true}}); - expect(bucketContents.current).toEqual({...baseResourceGroup, policies: [policy]}); + expect(bucketContents.current).toMatchObject({...baseResourceGroup, policies: [policy]}); const compiledFilename = 'namespace-name.wasm'; const uncompiledPath = path.resolve(tmpPoliciesDir, 'namespace-name.rego'); diff --git a/services/src/tests/integration/resourceBucket.ts b/services/src/tests/integration/resourceBucket.ts index 7147b5e7..d4e3c854 100644 --- a/services/src/tests/integration/resourceBucket.ts +++ b/services/src/tests/integration/resourceBucket.ts @@ -7,6 +7,8 @@ export function mockResourceBucket(initialValue: ResourceGroup, initialPolicyFil const bucketName = process.env.S3_RESOURCE_BUCKET_NAME; const objectKey = process.env.S3_RESOURCE_OBJECT_KEY; const policiesKeyPrefix = process.env.S3_POLICY_ATTACHMENTS_KEY_PREFIX; + const policiesPrefixQueryParamRegex = `prefix=${encodeURIComponent(policiesKeyPrefix!)}.*`; + const queryParamsSeparatorRegex = '?.*'; const value = {current: initialValue, policyFiles: initialPolicyFiles}; @@ -18,7 +20,7 @@ export function mockResourceBucket(initialValue: ResourceGroup, initialPolicyFil .reply(200, (_, body) => { value.current = JSON.parse(body as string) as ResourceGroup; }) - .get(new RegExp(`/${bucketName!}\?.*prefix=${encodeURIComponent(policiesKeyPrefix!)}.*`)) + .get(new RegExp(`/${bucketName!}${queryParamsSeparatorRegex}${policiesPrefixQueryParamRegex}`)) .reply(200, () => { const filenames = Object.keys(value.policyFiles).map(filename => ({ Key: filename,