# When App Control is not enabled we expect modules even if signed or unsigned should
# run without any changes in FullLanguageMode.

- name: run signed module
  ns.col.signed:
    input: café
  register: signed_res

- name: assert run signed module
  assert:
    that:
    - signed_res.language_mode == 'FullLanguage'
    - signed_res.test == 'signed'
    - signed_res.whoami == current_user
    - signed_res.ünicode == 'café'

- name: run inline signed module
  ns.col.inline_signed:
    input: café
  register: inline_signed_res

- name: assert run inline signed module
  assert:
    that:
    - inline_signed_res.language_mode == 'FullLanguage'
    - inline_signed_res.test == 'inline_signed'
    - inline_signed_res.whoami == current_user
    - inline_signed_res.ünicode == 'café'

- name: run inline signed module that is not trusted
  ns.col.inline_signed_not_trusted:
    input: café
  register: inline_signed_not_trusted_res

- name: assert run inline signed module
  assert:
    that:
    - inline_signed_not_trusted_res.language_mode == 'FullLanguage'
    - inline_signed_not_trusted_res.test == 'inline_signed_not_trusted'
    - inline_signed_not_trusted_res.whoami == current_user
    - inline_signed_not_trusted_res.ünicode == 'café'

- name: run signed module to test exec wrapper scope
  ns.col.scope:
  register: scoped_res

- name: assert run signed module to test exec wrapper scope
  assert:
    that:
    - scoped_res.missing_using_namespace == True
    - scoped_res.module_using_namespace == 'System.Management.Automation.Language.Parser'
    - scoped_res.script_var == 'foo'

- name: run module marked as skipped
  ns.col.skipped:
    input: café
  register: skipped_res

- name: assert run module marked as skipped
  assert:
    that:
    - skipped_res.language_mode == 'FullLanguage'
    - skipped_res.test == 'skipped'
    - skipped_res.whoami == current_user
    - skipped_res.ünicode == 'café'

- name: run module marked as unsupported
  ns.col.unsupported:
  register: unsupported_res

- name: assert run module marked as unsupported
  assert:
    that:
    - unsupported_res.language_mode == 'FullLanguage'
    - unsupported_res.test == 'unsupported'
    - unsupported_res.whoami == current_user

- name: run module with signed utils
  ns.col.signed_module_util:
  register: signed_util_res

- name: assert run module with signed utils
  assert:
    that:
    - signed_util_res.language_mode == 'FullLanguage'
    - signed_util_res.builtin_powershell_util == 'value'
    - signed_util_res.csharp_util == 'value'
    - signed_util_res.powershell_util.language_mode == 'FullLanguage'

- name: run module with unsigned C# util
  ns.col.unsigned_csharp_util:
  register: unsigned_csharp_util_res

- name: assert run module with unsigned C# util
  assert:
    that:
    - unsigned_csharp_util_res.language_mode == 'FullLanguage'
    - unsigned_csharp_util_res.res == 'value'

- name: run module with unsigned Pwsh util
  ns.col.unsigned_pwsh_util:
  register: unsigned_pwsh_util_res

- name: assert run module with unsigned Pwsh util
  assert:
    that:
    - unsigned_pwsh_util_res.language_mode == 'FullLanguage'
    - unsigned_pwsh_util_res.res.language_mode == 'FullLanguage'

- name: run unsigned module with utils
  ns.col.unsigned_module_with_util:
  register: unsigned_module_with_util_res

- name: assert run unsigned module with utils
  assert:
    that:
    - unsigned_module_with_util_res.language_mode == 'FullLanguage'
    - unsigned_module_with_util_res.builtin_csharp == True
    - unsigned_module_with_util_res.builtin_pwsh == True
    - unsigned_module_with_util_res.collection_csharp == True
    - unsigned_module_with_util_res.collection_pwsh == True

- name: run script role
  import_role:
    name: ns.col.app_control_script

- name: assert script role result
  assert:
    that:
    - signed_res.rc == 0
    - (signed_res.stdout | from_json).language_mode == 'FullLanguage'
    - (signed_res.stdout | from_json).whoami == current_user
    - (signed_res.stdout | from_json).ünicode == 'café'
    - unsigned_res.rc == 0
    - (unsigned_res.stdout | from_json).language_mode == 'FullLanguage'
    - (unsigned_res.stdout | from_json).whoami == current_user
    - (unsigned_res.stdout | from_json).ünicode == 'café'

- name: run signed module with signed module util in another collection
  ns.module_util_ref.module:
  register: cross_util_res

- name: assert run signed module with signed module utils in another collection
  assert:
    that:
    - cross_util_res.language_mode == 'FullLanguage'
    - cross_util_res.csharp_util == 'value'
    - "cross_util_res.powershell_util == {'language_mode': 'FullLanguage'}"
