<commit_before>Feature: Apply command with allowed accounts

  Background:
    Given a file named "stack_master.yml" with:
      """
      stack_defaults:
        allowed_accounts:
          - '11111111'
      stacks:
        us_east_1:
          myapp_vpc:
            template: myapp.rb
          myapp_db:
            template: myapp.rb
            allowed_accounts: '22222222'
          myapp_web:
            template: myapp.rb
            allowed_accounts: []
      """
    And a directory named "templates"
    And a file named "templates/myapp.rb" with:
      """
      SparkleFormation.new(:myapp) do
        description "Test template"
        set!('AWSTemplateFormatVersion', '2010-09-09')
      end
      """

  Scenario: Run apply with stack inheriting allowed accounts from stack defaults
    Given I stub the following stack events:
      | stack_id | event_id | stack_name | logical_resource_id | resource_status | resource_type              | timestamp           |
      | 1        | 1        | myapp-vpc  | myapp-vpc           | CREATE_COMPLETE | AWS::CloudFormation::Stack | 2020-10-29 00:00:00 |
    When I use the account "11111111"
    And I run `stack_master apply us-east-1 myapp-vpc`
    And the output should match /2020-10-29 00:00:00 (\+|\-)[0-9]{4} myapp-vpc AWS::CloudFormation::Stack CREATE_COMPLETE/
    Then the exit status should be 0

  Scenario: Run apply with stack overriding allowed accounts with its own list
    Given I stub the following stack events:
      | stack_id | event_id | stack_name | logical_resource_id | resource_status | resource_type              | timestamp           |
      | 1        | 1        | myapp-db   | myapp-db            | CREATE_COMPLETE | AWS::CloudFormation::Stack | 2020-10-29 00:00:00 |
    When I use the account "11111111"
    And I run `stack_master apply us-east-1 myapp-db`
    And the output should contain all of these lines:
      | Account '11111111' is not an allowed account. Allowed accounts are ["22222222"].|
    Then the exit status should be 0

  Scenario: Run apply with stack overriding allowed accounts to allow all accounts
    Given I stub the following stack events:<commit_msg>stack_master apply should exit 1 if account not allowed<commit_after>Feature: Apply command with allowed accounts

  Background:
    Given a file named "stack_master.yml" with:
      """
      stack_defaults:
        allowed_accounts:
          - '11111111'
      stacks:
        us_east_1:
          myapp_vpc:
            template: myapp.rb
          myapp_db:
            template: myapp.rb
            allowed_accounts: '22222222'
          myapp_web:
            template: myapp.rb
            allowed_accounts: []
      """
    And a directory named "templates"
    And a file named "templates/myapp.rb" with:
      """
      SparkleFormation.new(:myapp) do
        description "Test template"
        set!('AWSTemplateFormatVersion', '2010-09-09')
      end
      """

  Scenario: Run apply with stack inheriting allowed accounts from stack defaults
    Given I stub the following stack events:
      | stack_id | event_id | stack_name | logical_resource_id | resource_status | resource_type              | timestamp           |
      | 1        | 1        | myapp-vpc  | myapp-vpc           | CREATE_COMPLETE | AWS::CloudFormation::Stack | 2020-10-29 00:00:00 |
    When I use the account "11111111"
    And I run `stack_master apply us-east-1 myapp-vpc`
    And the output should match /2020-10-29 00:00:00 (\+|\-)[0-9]{4} myapp-vpc AWS::CloudFormation::Stack CREATE_COMPLETE/
    Then the exit status should be 0

  Scenario: Run apply with stack overriding allowed accounts with its own list
    Given I stub the following stack events:
      | stack_id | event_id | stack_name | logical_resource_id | resource_status | resource_type              | timestamp           |
      | 1        | 1        | myapp-db   | myapp-db            | CREATE_COMPLETE | AWS::CloudFormation::Stack | 2020-10-29 00:00:00 |
    When I use the account "11<PASSWORD>"
    And I run `stack_master apply us-east-1 myapp-db`
    And the output should contain all of these lines:
      | Account '11111111' is not an allowed account. Allowed accounts are ["22222222"].|
    Then the exit status should be 1

  Scenario: Run apply with stack overriding allowed accounts to allow all accounts
    Given I stub the following stack events:
{'fraction_non_alphanumeric': 0.07870791628753412, 'fraction_numerical': 0.048908098271155595, 'mean_word_length': 2.3335860500379075, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 11, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2357279', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1237, 'n_words': 419}