Skip to content
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

Ensure the discovery endpoint is validated and all required fields ar… #750

Merged
merged 4 commits into from
Jan 23, 2024

Conversation

nc-fkl
Copy link
Contributor

@nc-fkl nc-fkl commented Jan 4, 2024

Ensure the discovery endpoint is validated and all required fields are verified

@@ -63,12 +63,59 @@ public function __construct(
$this->crypto = $crypto;
}

public function isDiscoveryEndpointValid($url) {
// Initialize cURL session
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Julius, refactored it

Comment on lines 100 to 105
} else {
// Set isReachable to false if http code wasn't 200
$result['isReachable'] = false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
// Set isReachable to false if http code wasn't 200
$result['isReachable'] = false;
}
}

No need for this else branch as isReachable is only set to true if the status code is 200 in line 86

$result['isReachable'] = false;
}
} catch (Exception $e) {
$result['isReachable'] = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, but still worth to catch and best log the exception here

Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two additional minor comments, otherwise this looks sane :)

@nc-fkl nc-fkl force-pushed the fix/validate-discovery-endpoint branch from eb085e8 to 50e9a29 Compare January 5, 2024 14:03
Copy link
Member

@julien-nc julien-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments as well, otherwise looks good 👍

$body = $response->getBody();

// Check if the request was successful
if ($httpCode == 200 && !empty($body)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($httpCode == 200 && !empty($body)) {
if ($httpCode === Http::STATUS_OK && !empty($body)) {

Use triple equal and use OCP\AppFramework\Http constants for HTTP response codes.

}
}
} catch (Exception $e) {
$this->logger->error('Error - discovery endpoint validation: ' . $e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->logger->error('Error - discovery endpoint validation: ' . $e);
$this->logger->error('Discovery endpoint validation error', ['exception' => $e]);

So we get more info on the exception.

@julien-nc julien-nc force-pushed the fix/validate-discovery-endpoint branch from 50e9a29 to ee13ccd Compare January 23, 2024 15:39
Signed-off-by: Julien Veyssier <[email protected]>
@julien-nc julien-nc self-requested a review January 23, 2024 15:44
@julien-nc julien-nc merged commit 3a51adb into main Jan 23, 2024
38 checks passed
@julien-nc julien-nc deleted the fix/validate-discovery-endpoint branch January 23, 2024 16:00
@julien-nc julien-nc mentioned this pull request Jan 29, 2024
Copy link

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants