summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/openssl_privatekey/tasks/main.yml28
-rw-r--r--test/integration/targets/openssl_privatekey/tests/validate.yml56
-rw-r--r--test/integration/targets/openssl_publickey/tasks/main.yml42
-rw-r--r--test/integration/targets/openssl_publickey/tests/validate.yml49
-rw-r--r--test/integration/targets/setup_openssl/tasks/main.yml10
5 files changed, 176 insertions, 9 deletions
diff --git a/test/integration/targets/openssl_privatekey/tasks/main.yml b/test/integration/targets/openssl_privatekey/tasks/main.yml
index 464f56e17e..d33134badd 100644
--- a/test/integration/targets/openssl_privatekey/tasks/main.yml
+++ b/test/integration/targets/openssl_privatekey/tasks/main.yml
@@ -12,4 +12,32 @@
path: '{{ output_dir }}/privatekey3.pem'
type: DSA
+- name: Generate privatekey4 - standard
+ openssl_privatekey:
+ path: '{{ output_dir }}/privatekey4.pem'
+
+- name: Delete privatekey4 - standard
+ openssl_privatekey:
+ state: absent
+ path: '{{ output_dir }}/privatekey4.pem'
+
+- name: Generate privatekey5 - standard - with passphrase
+ openssl_privatekey:
+ path: '{{ output_dir }}/privatekey5.pem'
+ passphrase: ansible
+ cipher: aes256
+
+- name: Generate privatekey5 - standard - idempotence
+ openssl_privatekey:
+ path: '{{ output_dir }}/privatekey5.pem'
+ passphrase: ansible
+ cipher: aes256
+ register: privatekey5_idempotence
+
+- name: Generate privatekey6 - standard - with non-ASCII passphrase
+ openssl_privatekey:
+ path: '{{ output_dir }}/privatekey6.pem'
+ passphrase: ànsïblé
+ cipher: aes256
+
- import_tasks: ../tests/validate.yml
diff --git a/test/integration/targets/openssl_privatekey/tests/validate.yml b/test/integration/targets/openssl_privatekey/tests/validate.yml
index ccbce924e5..b2e9d4789e 100644
--- a/test/integration/targets/openssl_privatekey/tests/validate.yml
+++ b/test/integration/targets/openssl_privatekey/tests/validate.yml
@@ -1,28 +1,70 @@
-- name: Validate privatekey1 (test)
+- name: Validate privatekey1 (test - RSA key with size 4096 bits)
shell: "openssl rsa -noout -text -in {{ output_dir }}/privatekey1.pem | grep Private | sed 's/Private-Key: (\\(.*\\) bit)/\\1/'"
register: privatekey1
-- name: Validate privatekey1 (assert)
+- name: Validate privatekey1 (assert - RSA key with size 4096 bits)
assert:
that:
- privatekey1.stdout == '4096'
-- name: Validate privatekey2 (test)
+- name: Validate privatekey2 (test - RSA key with size 2048 bits)
shell: "openssl rsa -noout -text -in {{ output_dir }}/privatekey2.pem | grep Private | sed 's/Private-Key: (\\(.*\\) bit)/\\1/'"
register: privatekey2
-- name: Validate privatekey2 (assert)
+- name: Validate privatekey2 (assert - RSA key with size 2048 bits)
assert:
that:
- privatekey2.stdout == '2048'
-- name: Validate privatekey3 (test)
+- name: Validate privatekey3 (test - DSA key with size 4096 bits)
shell: "openssl dsa -noout -text -in {{ output_dir }}/privatekey3.pem | grep Private | sed 's/Private-Key: (\\(.*\\) bit)/\\1/'"
register: privatekey3
-- name: Validate privatekey3 (assert)
+- name: Validate privatekey3 (assert - DSA key with size 4096 bits)
assert:
that:
- - privatekey1.stdout == '4096'
+ - privatekey3.stdout == '4096'
+
+
+- name: Validate privatekey4 (test - Ensure key has been removed)
+ stat:
+ path: '{{ output_dir }}/privatekey4.pem'
+ register: privatekey4
+
+- name: Validate privatekey4 (assert - Ensure key has been removed)
+ assert:
+ that:
+ - privatekey4.stat.exists == False
+
+
+- name: Validate privatekey5 (test - Passphrase protected key + idempotence)
+ shell: "openssl rsa -noout -text -in {{ output_dir }}/privatekey5.pem -passin pass:ansible | grep Private | sed 's/Private-Key: (\\(.*\\) bit)/\\1/'"
+ register: privatekey5
+ # Current version of OS/X that runs in the CI (10.11) does not have an up to date version of the OpenSSL library
+ # leading to this test to fail when run in the CI. However, this test has been run for 10.12 and has returned succesfully.
+ when: openssl_version.stdout|version_compare('0.9.8zh', '>=')
+
+- name: Validate privatekey5 (assert - Passphrase protected key + idempotence)
+ assert:
+ that:
+ - privatekey5.stdout == '4096'
+ when: openssl_version.stdout|version_compare('0.9.8zh', '>=')
+
+- name: Validate privatekey5 idempotence (assert - Passphrase protected key + idempotence)
+ assert:
+ that:
+ - not privatekey5_idempotence|changed
+
+
+- name: Validate privatekey6 (test - Passphrase protected key with non ascii character)
+ shell: "openssl rsa -noout -text -in {{ output_dir }}/privatekey6.pem -passin pass:ànsïblé | grep Private | sed 's/Private-Key: (\\(.*\\) bit)/\\1/'"
+ register: privatekey6
+ when: openssl_version.stdout|version_compare('0.9.8zh', '>=')
+
+- name: Validate privatekey6 (assert - Passphrase protected key with non ascii character)
+ assert:
+ that:
+ - privatekey6.stdout == '4096'
+ when: openssl_version.stdout|version_compare('0.9.8zh', '>=')
diff --git a/test/integration/targets/openssl_publickey/tasks/main.yml b/test/integration/targets/openssl_publickey/tasks/main.yml
index 8f8a7a3452..0f88d7fca4 100644
--- a/test/integration/targets/openssl_publickey/tasks/main.yml
+++ b/test/integration/targets/openssl_publickey/tasks/main.yml
@@ -3,11 +3,51 @@
openssl_privatekey:
path: '{{ output_dir }}/privatekey.pem'
- - name: Generate publickey
+ - name: Generate publickey - PEM format
openssl_publickey:
path: '{{ output_dir }}/publickey.pub'
privatekey_path: '{{ output_dir }}/privatekey.pem'
+ - name: Generate publickey - OpenSSH format
+ openssl_publickey:
+ path: '{{ output_dir }}/publickey-ssh.pub'
+ privatekey_path: '{{ output_dir }}/privatekey.pem'
+ format: OpenSSH
+ # cryptography.hazmat.primitives import serialization.Encoding.OpenSSH and
+ # cryptography.hazmat.primitives import serialization.PublicFormat.OpenSSH constants
+ # appeared in version 1.4 of cryptography
+ when: cryptography_version.stdout|version_compare('1.4.0', '>=')
+
+ - name: Generate publickey2 - standard
+ openssl_publickey:
+ path: '{{ output_dir }}/publickey2.pub'
+ privatekey_path: '{{ output_dir }}/privatekey.pem'
+
+ - name: Delete publickey2 - standard
+ openssl_publickey:
+ state: absent
+ path: '{{ output_dir }}/publickey2.pub'
+ privatekey_path: '{{ output_dir }}/privatekey.pem'
+
+ - name: Generate privatekey3 - with passphrase
+ openssl_privatekey:
+ path: '{{ output_dir }}/privatekey3.pem'
+ passphrase: ansible
+ cipher: aes256
+
+ - name: Generate publickey3 - with passphrase protected privatekey
+ openssl_publickey:
+ path: '{{ output_dir }}/publickey3.pub'
+ privatekey_path: '{{ output_dir }}/privatekey3.pem'
+ privatekey_passphrase: ansible
+
+ - name: Generate publickey3 - with passphrase protected privatekey - idempotence
+ openssl_publickey:
+ path: '{{ output_dir }}/publickey3.pub'
+ privatekey_path: '{{ output_dir }}/privatekey3.pem'
+ privatekey_passphrase: ansible
+ register: publickey3_idempotence
+
- import_tasks: ../tests/validate.yml
when: pyopenssl_version.stdout|version_compare('16.0.0', '>=')
diff --git a/test/integration/targets/openssl_publickey/tests/validate.yml b/test/integration/targets/openssl_publickey/tests/validate.yml
index 8bf34c6d13..bcb835c82f 100644
--- a/test/integration/targets/openssl_publickey/tests/validate.yml
+++ b/test/integration/targets/openssl_publickey/tests/validate.yml
@@ -10,3 +10,52 @@
assert:
that:
- publickey_modulus.stdout == privatekey_modulus.stdout
+
+- name: Validate public key - OpenSSH format (test - privatekey's publickey)
+ shell: 'ssh-keygen -y -f {{ output_dir }}/privatekey.pem'
+ register: privatekey_publickey
+ when: cryptography_version.stdout|version_compare('1.4.0', '>=')
+
+- name: Validate public key - OpenSSH format (test - publickey)
+ slurp:
+ src: '{{ output_dir }}/publickey-ssh.pub'
+ register: publickey
+ when: cryptography_version.stdout|version_compare('1.4.0', '>=')
+
+- name: Validate public key - OpenSSH format (assert)
+ assert:
+ that:
+ - privatekey_publickey.stdout == '{{ publickey.content|b64decode }}'
+ when: cryptography_version.stdout|version_compare('1.4.0', '>=')
+
+- name: Validate publickey2 (test - Ensure key has been removed)
+ stat:
+ path: '{{ output_dir }}/publickey2.pub'
+ register: publickey2
+
+- name: Validate publickey2 (assert - Ensure key has been removed)
+ assert:
+ that:
+ - publickey2.stat.exists == False
+
+
+- name: Validate publickey3 (test - privatekey modulus)
+ shell: 'openssl rsa -noout -modulus -in {{ output_dir }}/privatekey3.pem -passin pass:ansible | openssl md5'
+ register: privatekey3_modulus
+ when: openssl_version.stdout|version_compare('0.9.8zh', '>=')
+
+- name: Validate publickey3 (test - publickey modulus)
+ shell: 'openssl rsa -pubin -noout -modulus < {{ output_dir }}/publickey3.pub | openssl md5'
+ register: publickey3_modulus
+ when: openssl_version.stdout|version_compare('0.9.8zh', '>=')
+
+- name: Validate publickey3 (assert)
+ assert:
+ that:
+ - publickey3_modulus.stdout == privatekey3_modulus.stdout
+ when: openssl_version.stdout|version_compare('0.9.8zh', '>=')
+
+- name: Validate publickey3 idempotence (assert)
+ assert:
+ that:
+ - not publickey3_idempotence|changed
diff --git a/test/integration/targets/setup_openssl/tasks/main.yml b/test/integration/targets/setup_openssl/tasks/main.yml
index 282ee43dd4..a49714cfde 100644
--- a/test/integration/targets/setup_openssl/tasks/main.yml
+++ b/test/integration/targets/setup_openssl/tasks/main.yml
@@ -20,6 +20,14 @@
name: pyOpenSSL
when: ansible_os_family == 'Darwin'
-- name: register openssl version
+- name: register pyOpenSSL version
command: python -c 'import OpenSSL; print(OpenSSL.__version__)'
register: pyopenssl_version
+
+- name: register openssl version
+ shell: "openssl version | cut -d' ' -f2"
+ register: openssl_version
+
+- name: register cryptography version
+ command: python -c 'import cryptography; print(cryptography.__version__)'
+ register: cryptography_version