Add per-auth-source cacert support to LDAP tests - #22217
Conversation
Reviewer's GuideRefactors LDAP tests to stop installing CA certs into the system trust store and instead use per-auth-source CA certificate configuration, adding helpers to fetch CA certs as PEM and new test coverage for the cacert behavior in both UI and CLI flows. Sequence diagram for fetching LDAP CA cert PEM per auth sourcesequenceDiagram
participant Test as LdapTest
participant Sat as SatelliteHost
participant IPA as IpaServer
participant AD as AdServer
Test->>Sat: get_ldap_cacert_pem(sat, "ipa", hostname)
activate Sat
Sat->>IPA: execute(curl -s http://hostname/ipa/config/ca.crt)
IPA-->>Sat: PEM CA cert
Sat-->>Test: PEM CA cert
deactivate Sat
Test->>Sat: get_ldap_cacert_pem(sat, "ad", hostname)
activate Sat
Sat->>Sat: execute(yum install cifs-utils)
Sat->>AD: execute(mount -t cifs //hostname/c$ /mnt)
Sat->>Sat: execute(cat /mnt/Users/Administrator/.../satqe-QE-SAT6-AD-CA.cer)
alt [certificate not in PEM]
Sat->>Sat: execute(openssl x509 -inform DER -in cert_path)
end
Sat->>Sat: execute(umount /mnt)
Sat-->>Test: PEM CA cert
deactivate Sat
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
21847d9 to
0fec79b
Compare
| module_target_sat.cli.LDAPAuthSource.info({'name': new_name}) | ||
|
|
||
| @pytest.mark.usefixtures("ldap_tear_down") | ||
| def test_positive_create_with_cacert_ipa(self, default_ipa_host, module_target_sat): |
There was a problem hiding this comment.
note for reviewers:
I can't say I'm exactly happy about this test, but I'm afraid we don't really have another way of covering this in an end-to-end fashion.
| :parametrized: yes | ||
| """ | ||
| ldap_data, auth_source = ldap_auth_source | ||
| with session, pytest.raises(AssertionError): |
There was a problem hiding this comment.
note for reviewers:
I'm not exactly happy about this. Due to https://projects.theforeman.org/issues/39552 , the webui only emits a toast notification saying "Error". Pretty hard to get more details out of that.
There was a problem hiding this comment.
Also, this is failing, will need to look at it more.
0fec79b to
87a2e40
Compare
|
|
PRT Result |
87a2e40 to
5da549c
Compare
adamruzicka
left a comment
There was a problem hiding this comment.
The run uncovered two things I did wrong in the tests, fixed those. rhsso tests are (most likely) failing due to expired certs.
a56f38a to
caa17a5
Compare
|
|
PRT Result |
caa17a5 to
19b44d3
Compare
|
|
PRT Result |
72003ec to
d56a4d9
Compare
Replace OS trust store certificate installation with the new per-auth-source cacert attribute from Foreman PR SatelliteQE#11107. The set_certificate_in_satellite() helpers are removed in favor of get_ldap_cacert_pem() which fetches the CA cert as a PEM string for direct use in auth source creation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d56a4d9 to
3380ff2
Compare
trigger: test-robottelo
pytest: >-
--verbose
tests/foreman/cli/test_ldapauthsource.py
tests/foreman/destructive/test_ldap_authentication.py
tests/foreman/ui/test_ldap_authentication.py
-k "test_positive_create_with_cacert_ipa or test_positive_create_with_https or test_ldaps_cacert_test_connection"
airgun: 2486
nailgun: 1430
theforeman:
foreman: 11107
hammer-cli-foreman: 658 |
trigger: test-robottelo
pytest: >-
--verbose
tests/foreman/cli/test_ldapauthsource.py
tests/foreman/destructive/test_ldap_authentication.py
tests/foreman/ui/test_ldap_authentication.py
-k "test_positive_create_with_cacert_ipa or test_positive_create_with_https or test_ldaps_cacert_test_connection"
airgun: 2486
nailgun: 1430
theforeman:
foreman: 11107
hammer-cli-foreman: 658 |
|
PRT Result |
1619b45 to
eecf486
Compare
trigger: test-robottelo
pytest: >-
--verbose
tests/foreman/destructive/test_ldap_authentication.py::test_positive_create_with_https\[AD_2019\]
airgun: 2486
nailgun: 1430
theforeman:
foreman: 11107
hammer-cli-foreman: 658 |
|
PRT Result |
70a5fca to
92a50b7
Compare
|
|
PRT Result |
92a50b7 to
705339a
Compare
trigger: test-robottelo
pytest: >-
--verbose
tests/foreman/cli/test_ldapauthsource.py
tests/foreman/destructive/test_ldap_authentication.py
tests/foreman/ui/test_ldap_authentication.py
-k "test_positive_create_with_cacert_ipa or test_positive_create_with_https or test_ldaps_cacert_test_connection"
airgun: 2486
nailgun: 1430
theforeman:
foreman: 11107
hammer-cli-foreman: 658 |
|
PRT Result |
|
|
PRT Result |
705339a to
60f75d9
Compare
Use the Satellite host cert as a wrong cacert on the first attempt instead of temporarily removing RH IT Root CAs from the trust store, making the test non-destructive. This, apart from making the test faster, also tests certificate pinning.
trigger: test-robottelo
pytest: >-
--verbose
tests/foreman/cli/test_ldapauthsource.py
tests/foreman/destructive/test_ldap_authentication.py
tests/foreman/ui/test_ldap_authentication.py
-k "test_positive_create_with_cacert_ipa or test_positive_create_with_https or test_ldaps_cacert_test_connection"
airgun: 2486
nailgun: 1430
theforeman:
foreman: 11107
hammer-cli-foreman: 658 |
1 similar comment
trigger: test-robottelo
pytest: >-
--verbose
tests/foreman/cli/test_ldapauthsource.py
tests/foreman/destructive/test_ldap_authentication.py
tests/foreman/ui/test_ldap_authentication.py
-k "test_positive_create_with_cacert_ipa or test_positive_create_with_https or test_ldaps_cacert_test_connection"
airgun: 2486
nailgun: 1430
theforeman:
foreman: 11107
hammer-cli-foreman: 658 |
|
PRT Result |
| } | ||
| ) | ||
| # No error details in toast https://projects.theforeman.org/issues/39552 | ||
| assert error.match('Danger alert: Error') |
There was a problem hiding this comment.
>>> with pytest.raises(AssertionError) as error:
... assert False, "This is a string"
... error.match("This is a")
...
True
So this doesn't really test whether some details follow, or it's just "Error".
There was a problem hiding this comment.
My two comments really mean "this will pass whether there are details or not, as long as there at least is 'Error'" - but that doesn't seem like it really tests anything.
There was a problem hiding this comment.
The issue on foreman's side got removed in the meantime, allowing me to match more closely
trigger: test-robottelo
pytest: >-
--verbose
tests/foreman/cli/test_ldapauthsource.py
tests/foreman/destructive/test_ldap_authentication.py
tests/foreman/ui/test_ldap_authentication.py
-k "test_positive_create_with_cacert_ipa or test_positive_create_with_https or test_ldaps_cacert_test_connection"
airgun: 2486
nailgun: 1430
theforeman:
foreman: 11107
hammer-cli-foreman: 658 |
|
PRT Result |
| backup_dir = '/tmp/ca-backup' | ||
| module_target_sat.execute(f'mkdir -p {backup_dir}') | ||
| module_target_sat.execute(f'mv {anchors}/*-IT-Root-CA.pem {backup_dir}/') | ||
| module_target_sat.execute('update-ca-trust extract') |
There was a problem hiding this comment.
Technically, extract isn't necessary. Just FYI, this is ok.
lhellebr
left a comment
There was a problem hiding this comment.
LGTM. I like this PR, it's great coverage improvement and even improves the structure a bit. Thanks, Adam!
Optionally, you can add some test cases with incorrect and invalid (as in, not a validly formatted) cert.
Problem Statement
theforeman/foreman#11107 adds a cacert attribute to ldap auth servers which obsoletes the old way of handling ca certs (by including in the system trust store).
Solution
Switch to per-source CA cert handling.
Related Issues
https://redhat.atlassian.net/browse/SAT-45933
https://redhat.atlassian.net/browse/SAT-46986
Requires:
Summary by Sourcery
Switch LDAP authentication tests to use per-auth-source CA certificates instead of system trust store configuration.
New Features:
Enhancements:
Tests: