Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent validations on encrypted values #1092

Merged
merged 4 commits into from
Jun 24, 2024

Conversation

mdonnalley
Copy link
Contributor

What does this PR do?

Prevent validation from being re-run on encrypted values

Testing

Create a plugin using sf dev generate plugin and add this command:

import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Config } from '@salesforce/core';

// eslint-disable-next-line sf-plugin/command-example
export default class StoreToken extends SfCommand<void> {
  // eslint-disable-next-line sf-plugin/no-hardcoded-messages-commands
  public static readonly summary = 'Programmatically set a token in the global config';

  public static readonly flags = {
    token: Flags.string({
      required: true,
      // eslint-disable-next-line sf-plugin/no-hardcoded-messages-flags
      summary: 'a token to store',
    }),
  };

  public async run(): Promise<void> {
    const { flags } = await this.parse(StoreToken);

    const config = await Config.create({ isGlobal: true, encryptedKeys: ['local-web-server-identity-token'] });
    Config.addAllowedProperties([
      {
        key: 'local-web-server-identity-token',
        description: 'Token for local web server identity',
        encrypted: true,
        input: {
          validator: (value): boolean => typeof value === 'string' && value.startsWith('123'),
          failedMessage: 'Token must start with 123',
        },
      },
    ]);
    config.set('local-web-server-identity-token', flags.token);

    await config.write();

    this.log('Done!');
  }
}

Without this change, it will fail validation since the validator is rerun during write (which calls this.cryptProperties(true), which calls set, which is was calls all the validators)

With the change, the validator is called just once during the initial set for encrypted properties

What issues does this PR fix or reference?

@W-16049112@

@mdonnalley mdonnalley requested a review from a team as a code owner June 20, 2024 15:47
@mshanemc
Copy link
Contributor

error replicates using QA as described

✅ --token abc still fails
✅ global config file has an encrypted value

@mshanemc mshanemc merged commit 50d2a91 into main Jun 24, 2024
73 checks passed
@mshanemc mshanemc deleted the mdonnalley/prevent-validation-on-encrypted-value branch June 24, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants