Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeresk committed Jun 18, 2020
1 parent 5d3dc43 commit 9729e3c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion services/src/modules/resource-repository/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const baseResourceGroup = {
upstreams: [],
upstreamClientCredentials: [],
policies: [],
policyAttachments: {},
};

describe('Create resource', () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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],
});
Expand All @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion services/src/tests/integration/resourceBucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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,
Expand Down

0 comments on commit 9729e3c

Please sign in to comment.