ansible/test/integration/targets/win_find/tasks/tests.yml
Jordan Borean fcdebe41e9
win_find - Refactor for better performance and alignment to find (#65536)
* win_find - refactor to make more performance and use newer style

* win_find - refactor for performance improvements and alignment to find

* More path alignment to find

* Fix yamllint error
2019-12-06 10:01:11 +10:00

755 lines
28 KiB
YAML

---
- name: expected skip when paths to a file
win_find:
paths: "{{win_find_dir}}\\single\\large.ps1"
register: actual
- name: assert skip when path is set to a file
assert:
that:
- not actual is changed
- actual.examined == 0
- actual.files == []
- actual.matched == 0
- actual.warnings == ["Argument path '" + win_find_dir + "\\single\\large.ps1' is a file not a directory, skipping"]
- name: expect skip when path is set to a non existent folder
win_find:
paths: "{{win_find_dir}}\\thisisafakefolder"
register: actual
- name: assert skip when path is set to a non existent folder
assert:
that:
- not actual is changed
- actual.examined == 0
- actual.files == []
- actual.matched == 0
- actual.warnings == ["Argument path '" + win_find_dir + "\\thisisafakefolder' does not exist, skipping"]
- name: get files in single directory
win_find:
paths: "{{win_find_dir}}\\single"
register: actual
- name: assert get files in single directory
assert:
that:
- not actual is changed
- actual.examined == 5
- actual.matched == 4
- actual.files[0].attributes == 'Archive'
- actual.files[0].checksum == 'f8d100cdcf0e6c1007db2f8dd0b7ee2884df89af'
- actual.files[0].creationtime == 1477984205
- actual.files[0].exists == True
- actual.files[0].extension == '.ps1'
- actual.files[0].filename == 'large.ps1'
- actual.files[0].hlnk_targets == []
- actual.files[0].isarchive == True
- actual.files[0].isdir == False
- actual.files[0].ishidden == False
- actual.files[0].isjunction == False
- actual.files[0].islnk == False
- actual.files[0].isreadonly == False
- actual.files[0].isreg == True
- actual.files[0].isshared == False
- actual.files[0].lastaccesstime == 1477984205
- actual.files[0].lastwritetime == 1477984205
- actual.files[0].lnk_source == None
- actual.files[0].lnk_target == None
- actual.files[0].nlink == 1
- actual.files[0].owner == 'BUILTIN\\Administrators'
- actual.files[0].path == win_find_dir + '\\single\\large.ps1'
- actual.files[0].sharename == None
- actual.files[0].size == 260002
- actual.files[1].attributes == 'Archive'
- actual.files[1].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[1].creationtime == 1477984205
- actual.files[1].exists == True
- actual.files[1].extension == '.log'
- actual.files[1].filename == 'out_20161101-091005.log'
- actual.files[1].hlnk_targets == []
- actual.files[1].isarchive == True
- actual.files[1].isdir == False
- actual.files[1].ishidden == False
- actual.files[1].isjunction == False
- actual.files[1].islnk == False
- actual.files[1].isreadonly == False
- actual.files[1].isreg == True
- actual.files[1].isshared == False
- actual.files[1].lastaccesstime == 1477984205
- actual.files[1].lastwritetime == 1477984205
- actual.files[1].lnk_source == None
- actual.files[1].lnk_target == None
- actual.files[1].nlink == 1
- actual.files[1].owner == 'BUILTIN\\Administrators'
- actual.files[1].path == win_find_dir + '\\single\\out_20161101-091005.log'
- actual.files[1].sharename == None
- actual.files[1].size == 14
- actual.files[2].attributes == 'Archive'
- actual.files[2].checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
- actual.files[2].creationtime == 1477984205
- actual.files[2].exists == True
- actual.files[2].extension == '.ps1'
- actual.files[2].filename == 'small.ps1'
- actual.files[2].hlnk_targets == []
- actual.files[2].isarchive == True
- actual.files[2].isdir == False
- actual.files[2].ishidden == False
- actual.files[2].isjunction == False
- actual.files[2].islnk == False
- actual.files[2].isreadonly == False
- actual.files[2].isreg == True
- actual.files[2].isshared == False
- actual.files[2].lastaccesstime == 1477984205
- actual.files[2].lastwritetime == 1477984205
- actual.files[2].lnk_source == None
- actual.files[2].lnk_target == None
- actual.files[2].nlink == 1
- actual.files[2].owner == 'BUILTIN\\Administrators'
- actual.files[2].path == win_find_dir + '\\single\\small.ps1'
- actual.files[2].sharename == None
- actual.files[2].size == 1
- actual.files[3].attributes == 'Archive'
- actual.files[3].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[3].creationtime == 1477984205
- actual.files[3].exists == True
- actual.files[3].extension == '.ps1'
- actual.files[3].filename == 'test.ps1'
- actual.files[3].hlnk_targets == []
- actual.files[3].isarchive == True
- actual.files[3].isdir == False
- actual.files[3].ishidden == False
- actual.files[3].isjunction == False
- actual.files[3].islnk == False
- actual.files[3].isreadonly == False
- actual.files[3].isreg == True
- actual.files[3].isshared == False
- actual.files[3].lastaccesstime == 1477984205
- actual.files[3].lastwritetime == 1477984205
- actual.files[3].lnk_source == None
- actual.files[3].lnk_target == None
- actual.files[3].nlink == 1
- actual.files[3].owner == 'BUILTIN\\Administrators'
- actual.files[3].path == win_find_dir + '\\single\\test.ps1'
- actual.files[3].sharename == None
- actual.files[3].size == 14
- name: find hidden files
win_find:
paths: ['{{win_find_dir}}\\single', '{{win_find_dir}}\\nested']
hidden: True
register: actual
- name: assert get files in single directory
assert:
that:
- not actual is changed
- actual.examined == 11
- actual.matched == 1
- actual.files[0].attributes == 'Hidden, Archive'
- actual.files[0].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[0].creationtime == 1477984205
- actual.files[0].exists == True
- actual.files[0].extension == '.ps1'
- actual.files[0].filename == 'hidden.ps1'
- actual.files[0].hlnk_targets == []
- actual.files[0].isarchive == True
- actual.files[0].isdir == False
- actual.files[0].ishidden == True
- actual.files[0].isjunction == False
- actual.files[0].islnk == False
- actual.files[0].isreadonly == False
- actual.files[0].isreg == True
- actual.files[0].isshared == False
- actual.files[0].lastaccesstime == 1477984205
- actual.files[0].lastwritetime == 1477984205
- actual.files[0].lnk_source == None
- actual.files[0].lnk_target == None
- actual.files[0].nlink == 1
- actual.files[0].owner == 'BUILTIN\\Administrators'
- actual.files[0].path == win_find_dir + '\\single\\hidden.ps1'
- actual.files[0].sharename == None
- actual.files[0].size == 14
- name: find file based on pattern
win_find:
paths: '{{win_find_dir}}\\single'
patterns: ['*.log', 'out_*']
register: actual_pattern
- name: find file based on pattern regex
win_find:
paths: '{{win_find_dir}}\\single'
patterns: "out_\\d{8}-\\d{6}.log"
use_regex: True
register: actual_regex
- name: assert find file based on pattern
assert:
that:
- not actual_pattern is changed
- actual_pattern.examined == 5
- actual_pattern.matched == 1
- actual_pattern.files[0].attributes == 'Archive'
- actual_pattern.files[0].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual_pattern.files[0].creationtime == 1477984205
- actual_pattern.files[0].exists == True
- actual_pattern.files[0].extension == '.log'
- actual_pattern.files[0].filename == 'out_20161101-091005.log'
- actual_pattern.files[0].hlnk_targets == []
- actual_pattern.files[0].isarchive == True
- actual_pattern.files[0].isdir == False
- actual_pattern.files[0].ishidden == False
- actual_pattern.files[0].isjunction == False
- actual_pattern.files[0].islnk == False
- actual_pattern.files[0].isreadonly == False
- actual_pattern.files[0].isreg == True
- actual_pattern.files[0].isshared == False
- actual_pattern.files[0].lastaccesstime == 1477984205
- actual_pattern.files[0].lastwritetime == 1477984205
- actual_pattern.files[0].lnk_source == None
- actual_pattern.files[0].lnk_target == None
- actual_pattern.files[0].nlink == 1
- actual_pattern.files[0].owner == 'BUILTIN\\Administrators'
- actual_pattern.files[0].path == win_find_dir + '\\single\\out_20161101-091005.log'
- actual_pattern.files[0].sharename == None
- actual_pattern.files[0].size == 14
- actual_pattern == actual_regex
- name: find files with recurse set
win_find:
paths: "{{win_find_dir}}\\nested"
recurse: True
patterns: "*.ps1"
register: actual
- name: assert find files with recurse set
assert:
that:
- not actual is changed
- actual.examined == 8
- actual.matched == 3
- actual.files[0].attributes == 'Archive'
- actual.files[0].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[0].creationtime == 1477984205
- actual.files[0].exists == True
- actual.files[0].extension == '.ps1'
- actual.files[0].filename == 'file.ps1'
- actual.files[0].hlnk_targets == []
- actual.files[0].isarchive == True
- actual.files[0].isdir == False
- actual.files[0].ishidden == False
- actual.files[0].isjunction == False
- actual.files[0].islnk == False
- actual.files[0].isreadonly == False
- actual.files[0].isreg == True
- actual.files[0].isshared == False
- actual.files[0].lastaccesstime == 1477984205
- actual.files[0].lastwritetime == 1477984205
- actual.files[0].lnk_source == None
- actual.files[0].lnk_target == None
- actual.files[0].nlink == 1
- actual.files[0].owner == 'BUILTIN\\Administrators'
- actual.files[0].path == win_find_dir + '\\nested\\file.ps1'
- actual.files[0].sharename == None
- actual.files[0].size == 14
- actual.files[1].attributes == 'Archive'
- actual.files[1].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[1].creationtime == 1477984205
- actual.files[1].exists == True
- actual.files[1].extension == '.ps1'
- actual.files[1].filename == 'test.ps1'
- actual.files[1].hlnk_targets == []
- actual.files[1].isarchive == True
- actual.files[1].isdir == False
- actual.files[1].ishidden == False
- actual.files[1].isjunction == False
- actual.files[1].islnk == False
- actual.files[1].isreadonly == False
- actual.files[1].isreg == True
- actual.files[1].isshared == False
- actual.files[1].lastaccesstime == 1477984205
- actual.files[1].lastwritetime == 1477984205
- actual.files[1].lnk_source == None
- actual.files[1].lnk_target == None
- actual.files[1].nlink == 1
- actual.files[1].owner == 'BUILTIN\\Administrators'
- actual.files[1].path == win_find_dir + '\\nested\\sub-nest\\test.ps1'
- actual.files[1].sharename == None
- actual.files[1].size == 14
- actual.files[2].attributes == 'Archive'
- actual.files[2].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[2].creationtime == 1477984205
- actual.files[2].exists == True
- actual.files[2].extension == '.ps1'
- actual.files[2].filename == 'test.ps1'
- actual.files[2].hlnk_targets == []
- actual.files[2].isarchive == True
- actual.files[2].isdir == False
- actual.files[2].ishidden == False
- actual.files[2].isjunction == False
- actual.files[2].islnk == False
- actual.files[2].isreadonly == False
- actual.files[2].isreg == True
- actual.files[2].isshared == False
- actual.files[2].lastaccesstime == 1477984205
- actual.files[2].lastwritetime == 1477984205
- actual.files[2].lnk_source == None
- actual.files[2].lnk_target == None
- actual.files[2].nlink == 1
- actual.files[2].owner == 'BUILTIN\\Administrators'
- actual.files[2].path == win_find_dir + '\\nested\\test.ps1'
- actual.files[2].sharename == None
- actual.files[2].size == 14
- name: find files with recurse set and follow links
win_find:
paths: "{{win_find_dir}}\\nested"
recurse: True
follow: True
patterns: "*.ps1"
register: actual
- name: assert find files with recurse set and follow links
assert:
that:
- not actual is changed
- actual.examined == 10
- actual.matched == 4
- actual.files[0].attributes == 'Archive'
- actual.files[0].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[0].creationtime == 1477984205
- actual.files[0].exists == True
- actual.files[0].extension == '.ps1'
- actual.files[0].filename == 'file.ps1'
- actual.files[0].hlnk_targets == []
- actual.files[0].isarchive == True
- actual.files[0].isdir == False
- actual.files[0].ishidden == False
- actual.files[0].isjunction == False
- actual.files[0].islnk == False
- actual.files[0].isreadonly == False
- actual.files[0].isreg == True
- actual.files[0].isshared == False
- actual.files[0].lastaccesstime == 1477984205
- actual.files[0].lastwritetime == 1477984205
- actual.files[0].lnk_source == None
- actual.files[0].lnk_target == None
- actual.files[0].nlink == 1
- actual.files[0].owner == 'BUILTIN\\Administrators'
- actual.files[0].path == win_find_dir + '\\nested\\file.ps1'
- actual.files[0].sharename == None
- actual.files[0].size == 14
- actual.files[1].attributes == 'Archive'
- actual.files[1].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[1].creationtime == 1477984205
- actual.files[1].exists == True
- actual.files[1].extension == '.ps1'
- actual.files[1].filename == 'link.ps1'
- actual.files[1].hlnk_targets == []
- actual.files[1].isarchive == True
- actual.files[1].isdir == False
- actual.files[1].ishidden == False
- actual.files[1].isjunction == False
- actual.files[1].islnk == False
- actual.files[1].isreadonly == False
- actual.files[1].isreg == True
- actual.files[1].isshared == False
- actual.files[1].lastaccesstime == 1477984205
- actual.files[1].lastwritetime == 1477984205
- actual.files[1].lnk_source == None
- actual.files[1].lnk_target == None
- actual.files[1].nlink == 1
- actual.files[1].owner == 'BUILTIN\\Administrators'
- actual.files[1].path == win_find_dir + '\\nested\\link\\link.ps1'
- actual.files[1].sharename == None
- actual.files[1].size == 14
- actual.files[2].attributes == 'Archive'
- actual.files[2].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[2].creationtime == 1477984205
- actual.files[2].exists == True
- actual.files[2].extension == '.ps1'
- actual.files[2].filename == 'test.ps1'
- actual.files[2].hlnk_targets == []
- actual.files[2].isarchive == True
- actual.files[2].isdir == False
- actual.files[2].ishidden == False
- actual.files[2].isjunction == False
- actual.files[2].islnk == False
- actual.files[2].isreadonly == False
- actual.files[2].isreg == True
- actual.files[2].isshared == False
- actual.files[2].lastaccesstime == 1477984205
- actual.files[2].lastwritetime == 1477984205
- actual.files[2].lnk_source == None
- actual.files[2].lnk_target == None
- actual.files[2].nlink == 1
- actual.files[2].owner == 'BUILTIN\\Administrators'
- actual.files[2].path == win_find_dir + '\\nested\\sub-nest\\test.ps1'
- actual.files[2].sharename == None
- actual.files[2].size == 14
- actual.files[3].attributes == 'Archive'
- actual.files[3].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- actual.files[3].creationtime == 1477984205
- actual.files[3].exists == True
- actual.files[3].extension == '.ps1'
- actual.files[3].filename == 'test.ps1'
- actual.files[3].hlnk_targets == []
- actual.files[3].isarchive == True
- actual.files[3].isdir == False
- actual.files[3].ishidden == False
- actual.files[3].isjunction == False
- actual.files[3].islnk == False
- actual.files[3].isreadonly == False
- actual.files[3].isreg == True
- actual.files[3].isshared == False
- actual.files[3].lastaccesstime == 1477984205
- actual.files[3].lastwritetime == 1477984205
- actual.files[3].lnk_source == None
- actual.files[3].lnk_target == None
- actual.files[3].nlink == 1
- actual.files[3].owner == 'BUILTIN\\Administrators'
- actual.files[3].path == win_find_dir + '\\nested\\test.ps1'
- actual.files[3].sharename == None
- actual.files[3].size == 14
- name: find directories
win_find:
paths: "{{win_find_dir}}\\link-dest"
file_type: directory
register: actual
- name: assert find directories
assert:
that:
- not actual is changed
- actual.examined == 2
- actual.matched == 1
- actual.files[0].attributes == 'Directory'
- actual.files[0].checksum == None
- actual.files[0].creationtime == 1477984205
- actual.files[0].exists == True
- actual.files[0].extension == None
- actual.files[0].filename == 'sub-link'
- actual.files[0].hlnk_targets == []
- actual.files[0].isarchive == False
- actual.files[0].isdir == True
- actual.files[0].ishidden == False
- actual.files[0].isjunction == False
- actual.files[0].islnk == False
- actual.files[0].isreadonly == False
- actual.files[0].isreg == False
- actual.files[0].isshared == False
- actual.files[0].lastaccesstime == 1477984205
- actual.files[0].lastwritetime == 1477984205
- actual.files[0].lnk_source == None
- actual.files[0].lnk_target == None
- actual.files[0].nlink == 1
- actual.files[0].owner == 'BUILTIN\\Administrators'
- actual.files[0].path == win_find_dir + '\\link-dest\\sub-link'
- actual.files[0].sharename == None
- actual.files[0].size == None
- name: find directories recurse and follow with a broken link
win_find:
paths: "{{win_find_dir}}"
file_type: directory
recurse: True
follow: True
register: actual
- name: check directory count with recurse and follow is correct
assert:
that:
- not actual is changed
- actual.examined == 37
- actual.matched == 17
- actual.files[0].filename == 'broken-link'
- actual.files[0].isjunction == False
- actual.files[0].islnk == True
- actual.files[6].filename == 'junction-link'
- actual.files[6].isjunction == True
- actual.files[6].islnk == False
- actual.files[6].lnk_source == win_find_dir + '\\junction-link-dest'
- actual.files[11].filename == 'link'
- actual.files[11].islnk == True
- actual.files[11].lnk_source == win_find_dir + '\\link-dest'
- actual.files[15].filename == 'folder'
- actual.files[15].islnk == False
- actual.files[15].isshared == True
- actual.files[15].sharename == 'folder-share'
- name: filter files by size without byte specified
win_find:
paths: "{{win_find_dir}}\\single"
size: 260002
register: actual_without_byte
- name: filter files by size with byte specified
win_find:
paths: "{{win_find_dir}}\\single"
size: 253k
register: actual_with_byte
- name: assert filter files by size
assert:
that:
- not actual_without_byte is changed
- actual_without_byte.examined == 5
- actual_without_byte.matched == 1
- actual_without_byte.files[0].attributes == 'Archive'
- actual_without_byte.files[0].checksum == 'f8d100cdcf0e6c1007db2f8dd0b7ee2884df89af'
- actual_without_byte.files[0].creationtime == 1477984205
- actual_without_byte.files[0].exists == True
- actual_without_byte.files[0].extension == '.ps1'
- actual_without_byte.files[0].filename == 'large.ps1'
- actual_without_byte.files[0].hlnk_targets == []
- actual_without_byte.files[0].isarchive == True
- actual_without_byte.files[0].isdir == False
- actual_without_byte.files[0].ishidden == False
- actual_without_byte.files[0].isjunction == False
- actual_without_byte.files[0].islnk == False
- actual_without_byte.files[0].isreadonly == False
- actual_without_byte.files[0].isreg == True
- actual_without_byte.files[0].isshared == False
- actual_without_byte.files[0].lastaccesstime == 1477984205
- actual_without_byte.files[0].lastwritetime == 1477984205
- actual_without_byte.files[0].lnk_source == None
- actual_without_byte.files[0].lnk_target == None
- actual_without_byte.files[0].nlink == 1
- actual_without_byte.files[0].owner == 'BUILTIN\\Administrators'
- actual_without_byte.files[0].path == win_find_dir + '\\single\\large.ps1'
- actual_without_byte.files[0].sharename == None
- actual_without_byte.files[0].size == 260002
- actual_without_byte == actual_with_byte
- name: filter files by size (less than) without byte specified
win_find:
paths: "{{win_find_dir}}\\single"
size: -4
register: actual_without_byte
- name: filter files by size (less than) with byte specified
win_find:
paths: "{{win_find_dir}}\\single"
size: -4b
register: actual_with_byte
- name: assert filter files by size (less than) without byte specified
assert:
that:
- not actual_without_byte is changed
- actual_without_byte.examined == 5
- actual_without_byte.matched == 1
- actual_without_byte.files[0].attributes == 'Archive'
- actual_without_byte.files[0].checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
- actual_without_byte.files[0].creationtime == 1477984205
- actual_without_byte.files[0].exists == True
- actual_without_byte.files[0].extension == '.ps1'
- actual_without_byte.files[0].filename == 'small.ps1'
- actual_without_byte.files[0].hlnk_targets == []
- actual_without_byte.files[0].isarchive == True
- actual_without_byte.files[0].isdir == False
- actual_without_byte.files[0].ishidden == False
- actual_without_byte.files[0].isjunction == False
- actual_without_byte.files[0].islnk == False
- actual_without_byte.files[0].isreadonly == False
- actual_without_byte.files[0].isreg == True
- actual_without_byte.files[0].isshared == False
- actual_without_byte.files[0].lastaccesstime == 1477984205
- actual_without_byte.files[0].lastwritetime == 1477984205
- actual_without_byte.files[0].lnk_source == None
- actual_without_byte.files[0].lnk_target == None
- actual_without_byte.files[0].nlink == 1
- actual_without_byte.files[0].owner == 'BUILTIN\\Administrators'
- actual_without_byte.files[0].path == win_find_dir + '\\single\\small.ps1'
- actual_without_byte.files[0].sharename == None
- actual_without_byte.files[0].size == 1
- actual_without_byte == actual_with_byte
# For dates we cannot assert against expected as the times change, this is a poor mans attempt at testing
- name: filter files by age without unit specified
win_find:
paths: "{{win_find_dir}}\\date"
age: 3600
register: actual_without_unit
- name: filter files by age with unit specified
win_find:
paths: "{{win_find_dir}}\\date"
age: 1h
register: actual_with_unit
- name: assert dates match each other
assert:
that:
- actual_without_unit == actual_with_unit
- actual_without_unit.matched == 1
- actual_without_unit.files[0].checksum == 'd1185139c47f5bc951e2e9135922fe31059206b1'
- actual_without_unit.files[0].path == win_find_dir + '\\date\\old.ps1'
- name: filter files by age (newer than) without unit specified
win_find:
paths: "{{win_find_dir}}\\date"
age: -3600
register: actual_without_unit
- name: filter files by age (newer than) without unit specified
win_find:
paths: "{{win_find_dir}}\\date"
age: -1h
register: actual_with_unit
- name: assert dates match each other
assert:
that:
- actual_without_unit == actual_with_unit
- actual_without_unit.matched == 1
- actual_without_unit.files[0].checksum == 'af99d0e98df4531b9f26c942f41d65c58766bfa9'
- actual_without_unit.files[0].path == win_find_dir + '\\date\\new.ps1'
- name: get list of files with md5 checksum
win_find:
paths: "{{win_find_dir}}\\single"
patterns: test.ps1
checksum_algorithm: md5
register: actual_md5_checksum
- name: assert md5 checksum value
assert:
that:
- actual_md5_checksum.files[0].checksum == 'd1713d0f1d2e8fae230328d8fd59de01'
- name: get list of files with sha1 checksum
win_find:
paths: "{{win_find_dir}}\\single"
patterns: test.ps1
checksum_algorithm: sha1
register: actual_sha1_checksum
- name: assert sha1 checksum value
assert:
that:
- actual_sha1_checksum.files[0].checksum == '8df33cee3325596517df5bb5aa980cf9c5c1fda3'
- name: get list of files with sha256 checksum
win_find:
paths: "{{win_find_dir}}\\single"
patterns: test.ps1
checksum_algorithm: sha256
register: actual_sha256_checksum
- name: assert sha256 checksum value
assert:
that:
- actual_sha256_checksum.files[0].checksum == 'c20d2eba7ffda0079812721b6f4e4e109e2f0c5e8cc3d1273a060df6f7d9f339'
- name: get list of files with sha384 checksum
win_find:
paths: "{{win_find_dir}}\\single"
patterns: test.ps1
checksum_algorithm: sha384
register: actual_sha384_checksum
- name: assert sha384 checksum value
assert:
that:
- actual_sha384_checksum.files[0].checksum == 'aed515eb216b9c7009ae8c4680f46c1e22004528b231aa0482a8587543bca47d3504e9f77e884eb2d11b2f9f5dc01651'
- name: get list of files with sha512 checksum
win_find:
paths: "{{win_find_dir}}\\single"
patterns: test.ps1
checksum_algorithm: sha512
register: actual_sha512_checksum
- name: assert sha512 checksum value
assert:
that:
- actual_sha512_checksum.files[0].checksum == '05abf64a68c4731699c23b4fc6894a36646fce525f3c96f9cf743b5d0c3bfd933dad0e95e449e3afe1f74d534d69a53b8f46cf835763dd42915813c897b02b87'
- name: get list of files without checksum
win_find:
paths: "{{win_find_dir}}\\single"
patterns: test.ps1
get_checksum: False
register: actual_no_checksum
- name: assert no checksum is returned
assert:
that:
- actual_no_checksum.files[0].checksum == None
# https://github.com/ansible/ansible/issues/26158
- name: get list of files in an empty nested directory
win_find:
paths: '{{win_find_dir}}\emptynested'
register: actual_empty_nested
- name: assert get list of files in an empty nested directory
assert:
that:
- actual_empty_nested.matched == 0
- name: create new folders for security tests
win_file:
path: '{{win_find_dir}}\{{item}}'
state: directory
with_items:
- secure-tests\secure\internal-folder
- secure-tests\open\internal-folder
- name: create random password for test user
set_fact:
test_win_find_password: password123! + {{ lookup('password', '/dev/null chars=ascii_letters,digits length=8') }}
- name: create test user who does not have access to secure folder
win_user:
name: '{{test_win_find_username}}'
password: '{{test_win_find_password}}'
state: present
groups:
- Users
- name: change owner of secure folder
win_owner:
path: '{{win_find_dir}}\secure-tests\secure'
user: BUILTIN\Administrators
recurse: yes
- name: set explicit inheritance of secure folder for the Administrators accounts
win_acl:
user: BUILTIN\Administrators
path: '{{win_find_dir}}\secure-tests\secure'
rights: FullControl
type: allow
state: present
inherit: None
- name: remove inheritance on the secure folder
win_acl_inheritance:
path: '{{win_find_dir}}\secure-tests\secure'
reorganize: no
state: absent
- name: run win_find with under-privileged account
win_find:
paths: '{{win_find_dir}}\secure-tests'
recurse: yes
file_type: directory
register: secure_result
become: yes
become_method: runas
become_user: '{{test_win_find_username}}'
vars:
ansible_become_password: '{{test_win_find_password}}'
- name: assert win_find only examined 2 files with under-privileged account
assert:
that:
- secure_result.examined == 3
- secure_result.matched == 3
- secure_result.files[0].path == win_find_dir + "\secure-tests\open"
- secure_result.files[1].path == win_find_dir + "\secure-tests\open\internal-folder"
- secure_result.files[2].path == win_find_dir + "\secure-tests\secure"