UNPKG

@pulumi/compliance-policies-unit-test-helpers

Version:

This repository contains a growing set of Compliance Policies to validate your infrastructure using Pulumi's Crossguard Policy-as-Code framework.

154 lines (153 loc) 6.81 kB
export * from "./version"; import * as policymanager from "@pulumi/compliance-policy-manager"; import { ResourceValidationArgs, StackValidationArgs, StackValidationPolicy, ResourceValidationPolicy } from "@pulumi/policy"; import { Resource } from "@pulumi/pulumi"; /** * The function createResourceValidationArgs() will create a ResourceValidationArgs using the `type` from * the specified `resourceClass` and `props` returned from the specified `argsFactory`. * The return type of the `argsFactory` is the unwrapped args bag for the resource, inferred * from the resource's constructor parameters. * * @param resourceClass The provider resource class. * @param args The resource class arguments to create the resource. * @param config The policy configuration. * @returns A resource validation used to assert against a policy. */ export declare function createResourceValidationArgs<TResource extends Resource, TArgs>(resourceClass: { new (name: string, args: TArgs, ...rest: any[]): TResource; }, // eslint-disable-line @typescript-eslint/no-shadow args: Record<string, any>, config?: Record<string, any>, resourceName?: string): ResourceValidationArgs; export interface PolicyViolation { message: string; urn?: string; } /** * The function createStackValidationArgs() will create a StackValidationArgs, simulating a stack that has a * single resource with the provided type and properties. * * @param resourceClass The provider resource class. * @param props The outputs of the resource. * @param config The stack validation configuration. * @returns A stack validation used to assert against a stack validation policy. */ export declare function createStackValidationArgs<TResource extends Resource, TArgs>(resourceClass: { new (name: string, args: TArgs, ...rest: any[]): TResource; }, props: any, config?: Record<string, any>, resourceName?: string): StackValidationArgs; /** * The function daysFromNow() returns "now", d days in the future or past. * * @param days Number of days. * @returns A Date object. */ export declare function daysFromNow(days: number): Date; /** * The function asserts the resource provided reports a violation. * * @param resPolicy A resource validation policy. * @param args Arguments for the resource validation policy. * @param wantViolation An expected policy violation. */ export declare function assertHasResourceViolation(resPolicy: ResourceValidationPolicy, args: ResourceValidationArgs, wantViolation: PolicyViolation): Promise<void>; /** * The function asserts the resource provided does NOT reports any violation. * * @param resPolicy A resource validation policy. * @param args Arguments for the resource validation policy. */ export declare function assertNoResourceViolations(resPolicy: ResourceValidationPolicy, args: ResourceValidationArgs): Promise<void>; /** * The function asserts the stack provided does NOT report any violation. * * @param stackPolicy A stack validation policy. * @param args Arguments for the stack validation policy. */ export declare function assertNoStackViolations(stackPolicy: StackValidationPolicy, args: StackValidationArgs): Promise<void>; /** * The function asserts the stack provided report a violation. * * @param stackPolicy A stack validation policy. * @param args Arguments for the stack validation policy. * @param wantViolation An expected violation. */ export declare function assertHasStackViolation(stackPolicy: StackValidationPolicy, args: StackValidationArgs, wantViolation: PolicyViolation): Promise<void>; /** * The function asserts the policy has been registered. * * @param policy A resource validation policy. */ export declare function assertResourcePolicyIsRegistered(policy: ResourceValidationPolicy): void; /** * The function asserts the policy name is as expected. * * @param policy A resource validation policy. * @param name The resource validation policy expected name. */ export declare function assertResourcePolicyName(policy: ResourceValidationPolicy, name: string): void; /** * The function asserts the policy has the correct enforcementLevel. * * @param policy A resource validation policy. */ export declare function assertResourcePolicyEnforcementLevel(policy: ResourceValidationPolicy): void; /** * The function asserts the policy has a sentence as a description. * * @param policy A resource validation policy. */ export declare function assertResourcePolicyDescription(policy: ResourceValidationPolicy): void; /** * The function asserts the policy has the expected policy metadata. * * @param policy A resource validation policy. * @param metadata The expected policy metadata. */ export declare function assertResourcePolicyRegistrationDetails(policy: ResourceValidationPolicy, metadata: policymanager.PolicyMetadata): void; /** * The function asserts some policies have been registered. */ export declare function assertHasRegisteredPolicies(): void; /** * The function asserts 1 or more policies are up for selection. */ export declare function assertHasRemainingPolicies(): void; /** * The function asserts the number of selectable policies is the same as the total of all registered policies. */ export declare function assertHasAllRemainingPolicies(): void; /** * The function asserts no more policies are selectable. */ export declare function assertHasNoRemainingPolicies(): void; /** * The function asserts an expected number of policies is selectable. * * @param expectedtedRemainingPolicyCount The expected number of remaining policies. */ export declare function assertExpectedRemainingPolicyCount(expectedtedRemainingPolicyCount: number): void; /** * The function asserts no policies are selected twice. * * @param filterPolicy A policy selection filter. */ export declare function assertNoDoubleSelection(filterPolicy: policymanager.FilterPolicyArgs): void; /** * The function asserts the enforcementLevel is applied when selecting policies. * * @param filterPolicy A policy selection filter. * @param enforcementLevel An expected policy enforcement level. */ export declare function assertSelectionEnforcementLevel(filterPolicy: policymanager.FilterPolicyArgs, enforcementLevel: string): void; /** * This function assert the code quality of a policy source file. * * @param suiteName The MochaJS suite name. * @param suiteFile The MochaJS source file for the current suite. Using `__filename` is usually sufficient. */ export declare function assertCodeQuality(suiteName?: string, suiteFile?: string): void; /** * This function asserts the supplied Policy Manager package version is identical * to the one included in this package. * * @param version The Policy Manager package version. */ export declare function assertPolicyManagerVersion(version: string): void;