Skip to content

Commit

Permalink
final update copyright and integration test before pr
Browse files Browse the repository at this point in the history
  • Loading branch information
yurnov committed Nov 29, 2024
1 parent 1eaa0c6 commit cb49e88
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
4 changes: 2 additions & 2 deletions plugins/modules/helm_registry_auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2024, Yuriy Novostavskiy <@yurnov>
# Copyright: © Ericsson AB 2024
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

Expand Down Expand Up @@ -39,7 +39,7 @@
description:
- Provide a URL for accessing the registry.
required: true
aliases: [ registry_url ]
aliases: [ registry_url ]
type: str
insecure:
description:
Expand Down
70 changes: 27 additions & 43 deletions tests/integration/targets/helm_registry_auth/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
register: _login_correct
failed_when: _login_correct.rc != 0

# - name: Clean up credentials to run test on clean environment
# ansible.builtin.shell: >-
# helm registry logout localhost:{{ registry_port }}
# register: _logout
# failed_when: _logout.rc != 0
- name: Clean up credentials to run test on clean environment
ansible.builtin.shell: >-
helm registry logout localhost:{{ registry_port }}
register: _logout
failed_when: _logout.rc != 0

- name: Create directory for helm chart
ansible.builtin.tempfile:
Expand All @@ -68,28 +68,22 @@
return_content: no
status_code: 200

# - name: Test module helm_registry_auth with correct credentials
# helm_registry_auth:
# username: "{{ username }}"
# password: "{{ password }}"
# registry: localhost:{{ registry_port }}
# state: present
# register: _helm_registry_auth_correct
# failed_when: _helm_registry_auth_correct.failed
- name: Test the registry with correct credentials (to be removed)
ansible.builtin.shell: >-
echo {{ password | quote }} | helm registry login localhost:{{ registry_port }}
-u {{ username }} --password-stdin
- name: Test module helm_registry_auth with correct credentials
helm_registry_auth:
username: "{{ username }}"
password: "{{ password }}"
registry: localhost:{{ registry_port }}
state: present
register: _helm_registry_auth_correct

- name: Assert that the registry is logged in
# Helm binary prints the message to stderr, refence: https://github.com/helm/helm/issues/13464
assert:
that:
- "'Login Succeeded' in _helm_registry_auth_correct.stderr"
# - "'{{ password }}' not in _helm_registry_auth_correct.command"
# - "'{{ password }}' not in _helm_registry_auth_correct.stdout"
# - "'{{ password }}' not in _helm_registry_auth_correct.stderr"
- "'{{ password }}' not in _helm_registry_auth_correct.command"
- "'{{ password }}' not in _helm_registry_auth_correct.stdout"
- "'{{ password }}' not in _helm_registry_auth_correct.stderr"

- name: Ensure that push to the registry is working
ansible.builtin.shell: >-
Expand All @@ -103,14 +97,10 @@
that: "'Pushed: localhost:{{ registry_port }}/test/k8s-monitoring' in _save_chart.stderr"


# - name: Test logout
# helm_registry_auth:
# registry: localhost:{{ registry_port }}
# state: absent
# register: _helm_registry_auth_logout
# failed_when: _helm_registry_auth_logout.failed
- name: Test logout (to be removed)
ansible.builtin.shell: helm registry logout localhost:{{ registry_port }}
- name: Test logout
helm_registry_auth:
registry: localhost:{{ registry_port }}
state: absent
register: _helm_registry_auth_logout

- name: Assert logout
Expand Down Expand Up @@ -138,18 +128,12 @@
- "_save_chart.rc != 0"
- "'localhost' not in _config_json.content | b64decode"

# - name: Test module helm_registry_auth with wrong credentials
# helm_registry_auth:
# username: "{{ username }}"
# password: "{{ wrong_password }}"
# registry: localhost:{{ registry_port }}
# state: present
# register: _helm_registry_auth_wrong
# failed_when: _helm_registry_auth_wrong.rc == 0
- name: Test module helm_registry_auth with wrong credentials (to be removed)
ansible.builtin.shell: >-
echo {{ wrong_password | quote }} | helm registry login localhost:{{ registry_port }}
-u {{ username }} --password-stdin
- name: Test module helm_registry_auth with wrong credentials
helm_registry_auth:
username: "{{ username }}"
password: "{{ wrong_password }}"
registry: localhost:{{ registry_port }}
state: present
register: _helm_registry_auth_wrong
failed_when: _helm_registry_auth_wrong.rc == 0

Expand All @@ -163,9 +147,9 @@
that:
- "'401 Unauthorized' in _helm_registry_auth_wrong.stderr"
- "_helm_registry_auth_wrong.rc != 0"
# - "'{{ wrong_password }}' not in _helm_registry_auth_correct.command"
# - "'{{ wrong_password }}' not in _helm_registry_auth_correct.stdout"
# - "'{{ wrong_password }}' not in _helm_registry_auth_correct.stderr"
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.command"
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stdout"
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stderr"
- "'localhost' not in _config_json.content | b64decode"

# Clean up
Expand Down

0 comments on commit cb49e88

Please sign in to comment.