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

win_credential - fix wildcard name #67549

Merged
merged 1 commit into from Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/win_credential-wildcard.yaml
@@ -0,0 +1,2 @@
bugfixes:
- win_credential - Fix issue that errors when trying to add a ``name`` with wildcards.
8 changes: 5 additions & 3 deletions lib/ansible/modules/windows/win_credential.ps1
Expand Up @@ -378,8 +378,10 @@ namespace Ansible.CredentialManager
using (SafeMemoryBuffer attributes = new SafeMemoryBuffer(attributeBytes.Length))
{
if (attributeBytes.Length != 0)
{
Marshal.Copy(attributeBytes, 0, attributes.DangerousGetHandle(), attributeBytes.Length);
credential.Attributes = attributes.DangerousGetHandle();
credential.Attributes = attributes.DangerousGetHandle();
}

NativeHelpers.CredentialCreateFlags createFlags = 0;
if (preserveExisting)
Expand Down Expand Up @@ -588,10 +590,10 @@ if ($state -eq "absent") {
$new_credential = New-Object -TypeName Ansible.CredentialManager.Credential
$new_credential.Type = $type
$new_credential.TargetName = $name
$new_credential.Comment = $comment
$new_credential.Comment = if ($comment) { $comment } else { [NullString]::Value }
$new_credential.Secret = $secret
$new_credential.Persist = $persistence
$new_credential.TargetAlias = $alias
$new_credential.TargetAlias = if ($alias) { $alias } else { [NullString]::Value }
$new_credential.UserName = $username

if ($null -ne $attributes) {
Expand Down
46 changes: 46 additions & 0 deletions test/integration/targets/win_credential/tasks/tests.yml
Expand Up @@ -366,6 +366,52 @@
that:
- not remove_cred_again is changed

# https://github.com/ansible/ansible/issues/67278
- name: create credential with wildcard
win_credential:
name: '*.{{ test_hostname }}'
type: domain_password
username: DOMAIN\username
secret: password
state: present
persistence: enterprise
register: wildcard_cred
vars: *become_vars

- name: get result of create credential with wildcard
test_cred_facts:
name: '*.{{ test_hostname }}'
type: domain_password
register: wildcard_cred_actual
vars: *become_vars

- name: assert create credential with wildcard
assert:
that:
- wildcard_cred is changed
- wildcard_cred_actual.name == '*.' ~ test_hostname

- name: remove credential with wildcard
win_credential:
name: '*.{{ test_hostname }}'
type: domain_password
state: absent
register: wildcard_remove
vars: *become_vars

- name: get result of remove credential with wildcard
test_cred_facts:
name: '*.{{ test_hostname }}'
type: domain_password
register: wildcard_remove_actual
vars: *become_vars

- name: assert remove credential with wildcard
assert:
that:
- wildcard_remove is changed
- not wildcard_remove_actual.exists

- name: create generic password (check mode)
win_credential:
name: '{{ test_hostname }}'
Expand Down