Skip to content

Commit

Permalink
DXCDT-252: Enable deletion of email provider (2/2) (#673)
Browse files Browse the repository at this point in the history
* Enabling deletion of email provider

* Adding tests for deleting email provider

* Updating docs too

* Re-recording tests and adding e2e testing readme

Co-authored-by: Will Vedder <will.vedder@okta.com>
Co-authored-by: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 3, 2023
1 parent dff62c6 commit 13cb88d
Show file tree
Hide file tree
Showing 6 changed files with 1,358 additions and 2,278 deletions.
7 changes: 5 additions & 2 deletions docs/excluding-from-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ roles: # roles configuration is not omitted

### Empty

Resource configuration that is explicitly defined as empty. For set-based configurations like hooks, organizations and actions, setting these configurations to an empty set expresses an intentional emptying of those resources. In practice, this would signal a deletion, so long as the [`AUTH0_ALLOW_DELETE` deletion configuration property](configuring-the-deploy-cli.md#AUTH0_ALLOW_DELETE) is enabled. For non-set-based resource configuration like tenant and branding, the concept of emptiness does not apply, will not trigger any deletions or removals.
Resource configuration that is explicitly defined as empty. For set-based configurations like hooks, organizations and actions, setting these configurations to an empty set expresses an intentional emptying of those resources. In practice, this would signal a deletion, so long as the [`AUTH0_ALLOW_DELETE` deletion configuration property](configuring-the-deploy-cli.md#AUTH0_ALLOW_DELETE) is enabled.

For non-set-based resource configuration like tenant, email provider and branding, the expected behavior when applying an explicitly empty configuration value will depend on the resource. The `tenant`, `branding`, `attackProtection`, and `guardianPhoneFactorSelectedProvider` resources cannot be deleted whereas the `emailProvider` resource can be deleted.

#### Example of emptiness

```yaml
hooks: [] # Empty hooks
connections: [] # Empty connections
tenant: {} # Effectively a no-op, emptiness does not apply to non-set resource config
tenant: {} # Effectively a no-op, cannot delete tenant
emailProvider: {} # Will delete email provider
```
---
Expand Down
6 changes: 2 additions & 4 deletions src/tools/auth0/handlers/emailProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import DefaultHandler from './default';
import { Asset, Assets } from '../../../types';
import logger from '../../../logger';

export const schema = { type: 'object' };

Expand Down Expand Up @@ -37,9 +36,8 @@ export default class EmailProviderHandler extends DefaultHandler {

if (Object.keys(emailProvider).length === 0) {
if (this.config('AUTH0_ALLOW_DELETE') === true) {
logger.warn(
'Setting email provider to empty object will delete the provider in future versions. The current inability to delete is considered a bug. For more details see: https://github.com/auth0/auth0-deploy-cli/issues/653'
);
await this.client.emailProvider.delete();
this.didDelete(existing);
}
return;
}
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/e2e-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ export function decodeBuffer(recordingResponse: Definition['response']) {
try {
const isArray = Array.isArray(recordingResponse);
if (!isArray) return recordingResponse; // Some Auth0 Management API endpoints aren't gzipped, we can tell this if they are an array or not
if (recordingResponse.length === 0) return []; // Empty arrays can be piped through as-is too

const decoded = Buffer.from(recordingResponse.join(''), 'hex');
const unzipped = zlib.gunzipSync(decoded).toString('utf-8');
return JSON.parse(unzipped);
} catch (err) {
throw new Error(`Error decoding nock hex:\n${err}`);
throw new Error(
`Error decoding nock response, likely when decoding the response buffer:\n${err}\nRecording response: ${recordingResponse}`
);
}
}

Expand Down
33 changes: 33 additions & 0 deletions test/e2e/e2e_recordings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# How to manage E2E testing recordings

## Re-recording

Ensure `AUTH0_E2E_TENANT_DOMAIN`, `AUTH0_E2E_CLIENT_ID`, `AUTH0_E2E_CLIENT_SECRET` env vars are set.

Then delete the recording file that you are attempting to re-record. Example: `rm test/e2e/recordings/should-deploy-while-deleting-resources-if-AUTH0_ALLOW_DELETE-is-true.json`

Finally, run the following command:

```shell
AUTH0_HTTP_RECORDINGS="record" npx ts-mocha --timeout=120000 -p tsconfig.json test/e2e/e2e.test.ts -g="<SPECIFIC_TEST_TO_TARGET>"
```

**Example:**

```shell
AUTH0_HTTP_RECORDINGS="record" npx ts-mocha --timeout=120000 -p tsconfig.json test/e2e/e2e.test.ts -g="AUTH0_ALLOW_DELETE is true"
```

## Running Tests w/ Recordings

**Run for all:**

```shell
AUTH0_HTTP_RECORDINGS="lockdown" npm run test:e2e:node-module
```

**Run a specific test:**

```shell
AUTH0_HTTP_RECORDINGS="lockdown" npx ts-mocha --timeout=120000 -p tsconfig.json test/e2e/e2e.test.ts -g="should deploy while deleting resources if AUTH0_ALLOW_DELETE is true"
```
Loading

0 comments on commit 13cb88d

Please sign in to comment.