-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
[IMP] auth_saml: download the provider metadata #602
Merged
OCA-git-bot
merged 2 commits into
OCA:15.0
from
gurneyalex:15.0-auth_saml-download_metadata
May 14, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIID7TCCAtWgAwIBAgIUDBX/LJ1BPZOhb2vrDnwIasyEi+AwDQYJKoZIhvcNAQEL | ||
BQAwgYUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMQ4wDAYDVQQH | ||
DAVQYXJpczEMMAoGA1UECgwDT0NBMQwwCgYDVQQLDANPQ0ExFDASBgNVBAMMC2V4 | ||
YW1wbGUuY29tMR8wHQYJKoZIhvcNAQkBFhB0ZXN0QGV4YW1wbGUuY29tMB4XDTIz | ||
MDEwMTExMDAyN1oXDTIzMDEzMTExMDAyN1owgYUxCzAJBgNVBAYTAkFVMR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FYmIRn0eHz8fpMAw2qk7mol6iao | ||
GQ== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC+B4tGvVD1pL+3 | ||
xm4Lv+llEdMHqypqZXBfJHvOHS/nXIfvEHL3GzjMlYqd5Gc4nDjoiiBiFj53I1YS | ||
Vtj4KRxzrPV4k42Ic204oDLTtW1+GKwa+JG/WQsTnpIcaBZ8hes64WqPoXXJN8rI | ||
u2rZFkHOZsxM0bvPz2s7aGp1NaqHKh/04Za15yszsSL0+cu2pQuFDKHqfjsqchd8 | ||
Ewsh5Abt39bIZTkKc7vKEeRL/nUT2AjqDkbRWi54FUUSsKWuOjRyUwmsVWlqc4bZ | ||
RIaAt8+SiZIi/1kvhKt4U3buxuFNuRVbFuTsA4IUJBxoEi9FOGlGsD1hG/Z0H9fj | ||
IiLtSus/AgMBAAECggEBAKuXUFJeHL7TNzMRAMmnT28uOypPiwtr8Z5X6Vtiy6DU | ||
0wIyDj3H3PAPkI2mcvaRSmngYAFyKJGX3N7OgTkElmZ1pWptgn3WDKf3MC4vQ2F7 | ||
kd0A20q3cuMSaskvzC5BFvmiFoD/wMYjlP7RDVhdWqqv9IbhVAAAQcnxLUANZ6CH | ||
/xrieGuYavs62pSu5fnke7zRozdD1Mb7/oolAnycaLuoi1eZBh8wW8EJyFSxcZ5A | ||
pYF5kNqbwAdOZ22Tygxwu7lnh8PUOKxf9pTmO6uUYAJcn/Z3ZHtnBYsjU/LkfNPV | ||
hYLu1bKftm6UEZYwCXE3/ygop1q648NvCvtJB+Gbj9ECgYEA8nB+hS+7MLgi/dv8 | ||
FCMJ9HBN76/nlwjOCTZIyIhCs5Jc6zJQGiDNLUFM/1mpBKUWWAss3g0dmJq32ish | ||
apsCUxabzWuKi44fDMEterJrGDWquyJK+jNPqfqOORLdMf0edNfZbjUxev7D52Ak | ||
4Ej3Ggy/fENd8QWLK6PZHV5X1MUCgYEAyKiWlawh7l8eBrba8UFQ4n1HiK/2uEud | ||
yQOLceSRmW/xC6ZCiR0ILinrtZWRxqQg+ZSS24hjnHhcdnRw8TRXx22TkTwGfAXW | ||
wKesPrtGJrn0ADuZwPkGewyeHPsisXNSiuGLPcLiOCoNNYgbIWJ2RknM1Xw+2p8C | ||
qYU8Si6l6DMCgYEA20v4ld7sExCszjZ72XcsXQhs5v+Vm9/iByEsSwA+XZJqLHFx | ||
VYEQNvxXeq8OnN37zR4msqDogY6J+XWEH5shSiksO28ofj3LRk1DJzZWeyqoSeem | ||
LJXXXKkAlw3COaJ9NzG8Qt0o6dmjORqVoK8/nTekyfFh+0+JaKsoDFG3XwUCgYBN | ||
tq2Ljj0d+wzAAPXO1kMjVO3tjGj7e53CinLpS2LwkCBFKMFAJVRTvLyjeSgaTNrQ | ||
jrBKAgrCQQNehT5wzJrqjA/JAfxo8EH6H3ZgXVuQCBjuNicYS9ossfhStRj8rPNd | ||
AnlRFDdVFUREZVBMn7u7AT4puJMHTOpVCVsOR/7NbQKBgApyR1WfsxZYi8vzVosQ | ||
jnMIW18lnZN3s6auyEvmpVowx0U0yd9QU3HHX1j8Kfq7D9uERCwBtIfn9fzZrZnu | ||
Xgbi9LMUT1z1jFXxJNgzaNmm0JHW9cD24BWNeQ60uxaRiGGmCyfmgqrGOXSn2R8w | ||
KoWEnnunZ9nehcD9dkWcH5zG | ||
-----END PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,16 @@ | |
import base64 | ||
import html | ||
import os | ||
import os.path as osp | ||
from copy import deepcopy | ||
from unittest.mock import patch | ||
|
||
import responses | ||
|
||
from odoo.exceptions import AccessDenied, UserError, ValidationError | ||
from odoo.tests import HttpCase, tagged | ||
|
||
from .fake_idp import FakeIDP | ||
from .fake_idp import CONFIG, FakeIDP | ||
|
||
|
||
@tagged("saml", "post_install", "-at_install") | ||
|
@@ -359,3 +363,56 @@ def test_disallow_user_password_when_changing_settings(self): | |
self.authenticate( | ||
user="[email protected]", password="NesTNSte9340D720te>/-A" | ||
) | ||
|
||
@responses.activate | ||
def test_download_metadata(self): | ||
expected_metadata = self.idp.get_metadata() | ||
responses.add( | ||
responses.GET, | ||
"http://localhost:8000/metadata", | ||
status=200, | ||
content_type="text/xml", | ||
body=expected_metadata, | ||
) | ||
self.saml_provider.idp_metadata_url = "http://localhost:8000/metadata" | ||
self.saml_provider.idp_metadata = "" | ||
self.saml_provider.action_refresh_metadata_from_url() | ||
self.assertEqual(self.saml_provider.idp_metadata, expected_metadata) | ||
|
||
@responses.activate | ||
def test_login_with_saml_metadata_empty(self): | ||
self.saml_provider.idp_metadata_url = "http://localhost:8000/metadata" | ||
self.saml_provider.idp_metadata = "" | ||
expected_metadata = self.idp.get_metadata() | ||
responses.add( | ||
responses.GET, | ||
"http://localhost:8000/metadata", | ||
status=200, | ||
content_type="text/xml", | ||
body=expected_metadata, | ||
) | ||
self.test_login_with_saml() | ||
self.assertEqual(self.saml_provider.idp_metadata, expected_metadata) | ||
|
||
@responses.activate | ||
def test_login_with_saml_metadata_key_changed(self): | ||
settings = deepcopy(CONFIG) | ||
settings["key_file"] = osp.join( | ||
osp.dirname(__file__), "data", "key_idp_expired.pem" | ||
) | ||
settings["cert"] = osp.join( | ||
osp.dirname(__file__), "data", "key_idp_expired.pem" | ||
) | ||
expired_idp = FakeIDP(settings=settings) | ||
self.saml_provider.idp_metadata = expired_idp.get_metadata() | ||
self.saml_provider.idp_metadata_url = "http://localhost:8000/metadata" | ||
up_to_date_metadata = self.idp.get_metadata() | ||
self.assertNotEqual(self.saml_provider.idp_metadata, up_to_date_metadata) | ||
responses.add( | ||
responses.GET, | ||
"http://localhost:8000/metadata", | ||
status=200, | ||
content_type="text/xml", | ||
body=up_to_date_metadata, | ||
) | ||
self.test_login_with_saml() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vincent-hatakeyama I think this is not the correct way to trigger an error when checking the signature to test the refresh (I'm not familiar enough with the SAML idp vs. sp internals). Could you offer a suggestion?
The goal is to get this https://github.com/OCA/server-auth/pull/602/files#diff-19fdbbb274613d822573aba74ad5575708e31bddf1688f6d909e589370f6ec3fR311 covered by a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And indeed, the block is not tested