-
Notifications
You must be signed in to change notification settings - Fork 24
Do not throw an exception when the samlAuthenticationLogger is used before forAuthentication() is called on it #130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace Surfnet\SamlBundle\Tests\Unit\Metadata; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use ReflectionMethod; | ||
| use Surfnet\SamlBundle\Metadata\MetadataFactory; | ||
|
|
||
| class MetadataFactoryTest extends TestCase | ||
| { | ||
| public function testGetCertificateData(): void | ||
| { | ||
| $publicKeyFile = __DIR__ . '/certificate.pem'; // File with test certificate in PEM format | ||
| // Read the public key file and remove the first and last lines and all newlines | ||
| $expectedCertificate = str_replace("\n", '', implode("", array_slice(file($publicKeyFile), 1, -1))); | ||
|
|
||
| // Setup a mock for the MetadataFactory with the real getCertificateData method | ||
| // and add the mocked File class to it | ||
| $metadataFactoryMock = $this->getMockBuilder(MetadataFactory::class) | ||
| ->disableOriginalConstructor() | ||
| ->onlyMethods(['getCertificateData']) | ||
| ->getMock(); | ||
|
|
||
| // Setup a reflection to call the private method | ||
| $reflectionMethod = new ReflectionMethod($metadataFactoryMock::class, 'getCertificateData'); | ||
|
|
||
| // Test getCertificateData method with a valid certificate | ||
| $result = $reflectionMethod->invoke($metadataFactoryMock, $publicKeyFile); | ||
| $this->assertEquals($expectedCertificate, $result); | ||
|
|
||
| // Test with an invalid certificate | ||
| $invalidPublicKeyFile = __DIR__ . '/invalid_certificate.pem'; // File with invalid certificate | ||
| $this->expectException(\RuntimeException::class); | ||
| $this->expectExceptionMessage('Could not parse PEM certificate in ' . $invalidPublicKeyFile); | ||
| $reflectionMethod->invoke($metadataFactoryMock, $invalidPublicKeyFile); | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| -----BEGIN CERTIFICATE----- | ||
| MIIDwTCCAqmgAwIBAgIUYuSUugwc4J4NyW9WGqYJ/liwM4owDQYJKoZIhvcNAQEL | ||
| BQAwcDELMAkGA1UEBhMCTkwxEDAOBgNVBAgMB1V0cmVjaHQxEDAOBgNVBAcMB1V0 | ||
| cmVjaHQxJzAlBgNVBAoMHkRldmVsb3BtZW50IERvY2tlciBlbnZpcm9ubWVudDEU | ||
| MBIGA1UEAwwLR2F0ZXdheSBJRFAwHhcNMjMwNTE3MTIxNTEyWhcNMzMwNTE0MTIx | ||
| NTEyWjBwMQswCQYDVQQGEwJOTDEQMA4GA1UECAwHVXRyZWNodDEQMA4GA1UEBwwH | ||
| VXRyZWNodDEnMCUGA1UECgweRGV2ZWxvcG1lbnQgRG9ja2VyIGVudmlyb25tZW50 | ||
| MRQwEgYDVQQDDAtHYXRld2F5IElEUDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC | ||
| AQoCggEBAM2ulQVs5WpbJOAf7Cv/VPDTJqbWHVdUxAmdwZJlcNTRKNFVp4aJzQ3d | ||
| piyiGghI5odnzU0/BWBoHZFNYPU/OFr/gzn6iJGxL63L9+mFgE8PR9HpkV5TaRnr | ||
| 21+nZ0EXWjDZk9Px0enERicCItTeQzAUJeA0A9miIcK5IKIz/zSBSR3c802SGD/V | ||
| elUqY7Z2/UJM97cT92L+4Fz+4zhxxoThbPbrR0CweiROIt82grdwg7zf0+b62MOu | ||
| VtqFh0yPLRAFfLc4LjHuxFUdUvOHVta7x74dwdmHikqfujM10XN+sNns3LDJde2y | ||
| PWchU6ktq7cjgbYfIW/vzVzafP1Jk40CAwEAAaNTMFEwHQYDVR0OBBYEFGYn6LWR | ||
| DZa7+YryUncIlwJB2VorMB8GA1UdIwQYMBaAFGYn6LWRDZa7+YryUncIlwJB2Vor | ||
| MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAJ57lcOF6PWWW56m | ||
| S2s5gKFImtfRFzlfiyHsF14L7+nQ5NjfOhpU0wRpnTjK91KP0wCwlxzGFXR8yfqf | ||
| BFJryIV7aDdYPH/RIkwVaNBI0fsD/ozlYb18seieDEGLvQtTlrmc0UNHtWz6FW3L | ||
| 2geM3ENaqpOATl1Ywp4EPML7Dh0CbhhyM8PnPCEsdclouIeP5/B9Swfk3omXehof | ||
| 6bkFbntqA03msFBiW50twkfKeKULcJGXo667hto27KNxZUauqtPbnAGpUQmge8nx | ||
| SQlN8RPwlvygVM4LVMF9qP9YxloTH0xVNwN4noZUhfMNsKoJ7Hg5Xulaok8oCqmz | ||
| EiSroEg= | ||
| -----END CERTIFICATE----- |
This file contains hidden or 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,23 @@ | ||
| -- | ||
| MIIDwTCCAqmgAwIBAgIUYuSUugwc4J4NyW9WGqYJ/liwM4owDQYJKoZIhvcNAQEL | ||
| BQAwcDELMAkG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z6FW3L | ||
| 2geM3ENaqpOATl1Ywp4EPML7Dh0CbhhyM8PnPCEsdclouIeP5/B9Swfk3omXehof | ||
| 6bkFbntqA03msFBiW50twkfKeKULcJGXo667hto27KNxZUauqtPbnAGpUQmge8nx | ||
| SQlN8RPwlvygVM4LVMF9qP9YxloTH0xVNwN4noZUhfMNsKoJ7Hg5Xulaok8oCqmz | ||
| EiSroEg= | ||
| -----END CERTIFICATE----- |
This file contains hidden or 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.
This will indeed prevent an exception from being raised, but if this logger is used, it should use
forAuthenticationfirst.If something needs to be logged in situations where we don't have a requestID, another logger should be used.
So I suspect this has something to do with the wrong logger being used after the Symfony upgrade.
It would be safe to merge, but then the sari in the logs might disappear in certain cases were a sari would be helpful.
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.
Agree with everything you said, except:
This patch can never make a sari disappear, all it does is not throw when the sari is not there.
E.g. when expectedInResponseTo is null here, for instance because of session troubles,
Stepup-saml-bundle/src/Security/Authentication/Handler/ProcessSamlAuthenticationHandler.php
Line 44 in 61eeee5
Or this could happen because the logger is used before forAuthentication() is called like you said.
These issues in the use of this logger should be addresses to, but the choice to make a log action throw hides valuable info, and does not help at all. I ran into this while debugging such an issue.
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.
Discussed with @pablothedude : The point is that without the exception a developer can use this class wrongly (i.e DI'ing it without calling forAuthentication()) and not notice this.