Skip to content

Commit 8b46e5f

Browse files
committed
Adding test cases for deletions
1 parent b236c87 commit 8b46e5f

25 files changed

+25364
-14
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
examples/
2+
test/e2e/testdata/**/**
23
local/
34
node_modules/
45
lib/

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ lib
77
node_modules
88
examples
99
test/**/*.json
10-
test/**/*.yaml
10+
test/**/*.yaml
11+
test/e2e/testdata

test/e2e/e2e-utils.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import { back as nockBack, BackMode, Definition } from 'nock';
55

66
export function decodeBuffer(recordingResponse: Definition['response']) {
77
try {
8-
// Decode the hex buffer that nock made
9-
const response = Array.isArray(recordingResponse)
10-
? recordingResponse.join('')
11-
: recordingResponse?.toString() || '';
12-
const decoded = Buffer.from(response, 'hex');
8+
const isArray = Array.isArray(recordingResponse);
9+
if (!isArray) return recordingResponse; // Some Auth0 Management API endpoints aren't gzipped, we can tell this if they are an array or not
10+
11+
const decoded = Buffer.from(recordingResponse.join(''), 'hex');
1312
const unzipped = zlib.gunzipSync(decoded).toString('utf-8');
1413
return JSON.parse(unzipped);
1514
} catch (err) {
@@ -50,6 +49,7 @@ export function sanitizeRecording(recording: Definition): Definition {
5049
'client_secret',
5150
'cert',
5251
'pkcs7',
52+
'key',
5353
]);
5454

5555
return sanitizedRecording;

test/e2e/e2e.test.ts

+124
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { expect } from 'chai';
22
import path from 'path';
3+
import fs from 'fs';
34
import { getFiles, existsMustBeDir } from '../../src/utils';
5+
import { load as yamlLoad } from 'js-yaml';
46
import { setupRecording, testNameToWorkingDirectory } from './e2e-utils';
57
import { dump, deploy } from '../../src';
68

@@ -58,6 +60,128 @@ describe('#end-to-end deploy', function () {
5860

5961
recordingDone();
6062
});
63+
64+
it('should deploy without deleting resources if AUTH0_ALLOW_DELETE is false', async function () {
65+
const { recordingDone } = await setupRecording(this.test?.title);
66+
67+
// Loading tenant with a good bit of config
68+
await deploy({
69+
input_file: `${__dirname}/testdata/lots-of-configuration/tenant.yaml`,
70+
config: {
71+
AUTH0_DOMAIN,
72+
AUTH0_CLIENT_ID,
73+
AUTH0_CLIENT_SECRET,
74+
AUTH0_ACCESS_TOKEN,
75+
AUTH0_ALLOW_DELETE: false,
76+
},
77+
});
78+
79+
// Applying configuration to clear tenant out
80+
await deploy({
81+
input_file: `${__dirname}/testdata/empty-tenant/tenant.yaml`,
82+
config: {
83+
AUTH0_DOMAIN,
84+
AUTH0_CLIENT_ID,
85+
AUTH0_CLIENT_SECRET,
86+
AUTH0_ACCESS_TOKEN,
87+
AUTH0_ALLOW_DELETE: false,
88+
},
89+
});
90+
91+
const workDirectory = testNameToWorkingDirectory(this.test?.title);
92+
93+
// Perform a subsequent dump to know the new state of remote
94+
await dump({
95+
output_folder: workDirectory,
96+
format: 'yaml',
97+
config: {
98+
AUTH0_DOMAIN,
99+
AUTH0_CLIENT_ID,
100+
AUTH0_CLIENT_SECRET,
101+
AUTH0_ACCESS_TOKEN,
102+
},
103+
});
104+
105+
const files = getFiles(workDirectory, ['.yaml']);
106+
expect(files).to.have.length(1);
107+
expect(files[0]).to.equal(path.join(workDirectory, 'tenant.yaml'));
108+
109+
const yaml = yamlLoad(fs.readFileSync(files[0]));
110+
111+
expect(yaml.emailTemplates.length).to.be.above(0);
112+
expect(yaml.rules.length).to.be.above(0);
113+
expect(yaml.pages.length).to.be.above(0);
114+
expect(yaml.clients.length).to.be.above(0);
115+
expect(yaml.databases.length).to.be.above(0);
116+
expect(yaml.connections.length).to.be.above(0);
117+
expect(yaml.roles.length).to.be.above(0);
118+
expect(yaml.guardianFactorProviders.length).to.be.above(0);
119+
expect(yaml.guardianFactorTemplates.length).to.be.above(0);
120+
expect(yaml.actions.length).to.be.above(0);
121+
expect(yaml.organizations.length).to.be.above(0);
122+
expect(yaml.logStreams.length).to.be.above(0);
123+
124+
recordingDone();
125+
});
126+
127+
it('should deploy while deleting resources if AUTH0_ALLOW_DELETE is true', async function () {
128+
const { recordingDone } = await setupRecording(this.test?.title);
129+
130+
// Loading tenant with a good bit of config
131+
await deploy({
132+
input_file: `${__dirname}/testdata/lots-of-configuration/tenant.yaml`,
133+
config: {
134+
AUTH0_DOMAIN,
135+
AUTH0_CLIENT_ID,
136+
AUTH0_CLIENT_SECRET,
137+
AUTH0_ACCESS_TOKEN,
138+
AUTH0_ALLOW_DELETE: true,
139+
},
140+
});
141+
142+
// Applying configuration to clear tenant out
143+
await deploy({
144+
input_file: `${__dirname}/testdata/empty-tenant/tenant.yaml`,
145+
config: {
146+
AUTH0_DOMAIN,
147+
AUTH0_CLIENT_ID,
148+
AUTH0_CLIENT_SECRET,
149+
AUTH0_ACCESS_TOKEN,
150+
AUTH0_ALLOW_DELETE: true,
151+
},
152+
});
153+
154+
const workDirectory = testNameToWorkingDirectory(this.test?.title);
155+
156+
// Perform a subsequent dump to know the new state of remote
157+
await dump({
158+
output_folder: workDirectory,
159+
format: 'yaml',
160+
config: {
161+
AUTH0_DOMAIN,
162+
AUTH0_CLIENT_ID,
163+
AUTH0_CLIENT_SECRET,
164+
AUTH0_ACCESS_TOKEN,
165+
},
166+
});
167+
168+
const files = getFiles(workDirectory, ['.yaml']);
169+
expect(files).to.have.length(1);
170+
expect(files[0]).to.equal(path.join(workDirectory, 'tenant.yaml'));
171+
172+
const yaml = yamlLoad(fs.readFileSync(files[0]));
173+
174+
expect(yaml.rules).to.have.length(0);
175+
expect(yaml.clients).to.have.length(2); //Accounting for Deploy CLI and Default App client
176+
expect(yaml.databases).to.have.length(1); // Default user database
177+
expect(yaml.connections).to.have.length(0);
178+
expect(yaml.roles).to.have.length(0);
179+
expect(yaml.actions).to.have.length(0);
180+
expect(yaml.organizations).to.have.length(0);
181+
expect(yaml.logStreams).to.have.length(0);
182+
183+
recordingDone();
184+
});
61185
});
62186

63187
describe('#end-to-end dump and deploy cycle', function () {

0 commit comments

Comments
 (0)