ansible/test/integration/targets/iosxr_user/tests/cli/auth.yaml
Nathaniel Case 2e76c89910
IOS XR cli tests move to network_cli (#34007)
* Update task definitions for network_cli

* Add connection to debug messages

* Specify connection for prepare task

* pc won't be around for connection=network_cli

* Assorted Python 3 fixes

* Give default port if ansible_ssh_port missing

* delegate -> connection

* Extend error regex
2017-12-20 11:26:09 -05:00

97 lines
3.2 KiB
YAML

---
- block:
- name: Create user with password
iosxr_user:
name: auth_user
state: present
configured_password: pass123
provider: "{{ cli }}"
- name: test login
expect:
command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version"
responses:
(?i)password: "pass123"
- name: test login with invalid password (should fail)
expect:
command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version"
responses:
(?i)password: "badpass"
ignore_errors: yes
register: results
- name: check that attempt failed
assert:
that:
- results.failed
- name: create user with private key (contents input)
iosxr_user:
name: auth_user
state: present
public_key_contents: "{{ lookup('file', \"{{ role_path }}/files/public.pub\") }}"
provider: "{{ cli }}"
- name: test login with private key
expect:
command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version"
responses:
(?i)password: 'pass123'
- name: remove user and key
iosxr_user:
name: auth_user
provider: "{{ cli }}"
state: absent
- name: test login with private key (should fail, no user)
expect:
command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version"
responses:
(?i)password: 'pass123'
ignore_errors: yes
register: results
- name: create user with private key (path input)
iosxr_user:
name: auth_user
state: present
public_key: "{{ role_path }}/files/public.pub"
provider: "{{ cli }}"
- name: test login with private key
expect:
command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version"
responses:
(?i)password: 'pass123'
ignore_errors: yes
- name: change private key for user
iosxr_user:
name: auth_user
state: present
public_key_contents: "{{ lookup('file', \"{{ role_path }}/files/public2.pub\") }}"
provider: "{{ cli }}"
# FIXME: pexpect fails with OSError: [Errno 5] Input/output error
- name: test login with invalid private key (should fail)
expect:
command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version"
responses:
(?i)password: "pass123"
ignore_errors: yes
register: results
- name: check that attempt failed
assert:
that:
- results.failed
always:
- name: delete user
iosxr_user:
name: auth_user
state: absent
provider: "{{ cli }}"
register: result