Skip to content

Commit

Permalink
Merge pull request #123 from jhiemstrawisc/pr-113-metadata-err-msg
Browse files Browse the repository at this point in the history
Pr 113 metadata err msg
  • Loading branch information
djw8605 authored May 23, 2023
2 parents b899d00 + e91ba59 commit 3d17d51
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/scitokens_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ SimpleCurlGet::GetStatus SimpleCurlGet::perform_start(const std::string &url) {
if (rv != CURLE_OK) {
throw CurlException("Failed to set CURLOPT_TIMEOUT.");
}
rv = curl_easy_setopt(m_curl.get(), CURLOPT_FOLLOWLOCATION, 1L);
if (rv != CURLE_OK) {
throw CurlException("Failed to set CURLOPT_FOLLOWLOCATION.");
}

{
auto mres = curl_multi_add_handle(m_curl_multi.get(), m_curl.get());
Expand All @@ -85,6 +89,20 @@ SimpleCurlGet::GetStatus SimpleCurlGet::perform_start(const std::string &url) {
return perform_continue();
}

std::string SimpleCurlGet::get_url() const {
if (!m_curl) {
return "";
}

char *url = nullptr;
auto rv = curl_easy_getinfo(m_curl.get(), CURLINFO_EFFECTIVE_URL, &url);
if (rv != CURLE_OK) {
return "";
}

return std::string(url);
}

SimpleCurlGet::GetStatus SimpleCurlGet::perform_continue() {
int still_running;
auto resm = curl_multi_perform(m_curl_multi.get(), &still_running);
Expand Down Expand Up @@ -649,17 +667,22 @@ std::unique_ptr<AsyncStatus> Validator::get_public_keys_from_web_continue(
picojson::value json_obj;
auto err = picojson::parse(json_obj, metadata);
if (!err.empty()) {
throw JsonException(err);
throw JsonException(
"JSON parse failure when downloading from the metadata URL " +
status->m_cget->get_url() + ": " + err);
}
if (!json_obj.is<picojson::object>()) {
throw JsonException(
"Metadata resource contains improperly-formatted JSON.");
throw JsonException("Metadata resource " +
status->m_cget->get_url() +
" contains "
"improperly-formatted JSON.");
}
auto top_obj = json_obj.get<picojson::object>();
auto iter = top_obj.find("jwks_uri");
if (iter == top_obj.end() || (!iter->second.is<std::string>())) {
throw JsonException(
"Metadata resource is missing 'jwks_uri' string value");
throw JsonException("Metadata resource " +
status->m_cget->get_url() +
" is missing 'jwks_uri' string value");
}
auto jwks_uri = iter->second.get<std::string>();
status->m_has_metadata = true;
Expand All @@ -684,7 +707,9 @@ std::unique_ptr<AsyncStatus> Validator::get_public_keys_from_web_continue(
auto err = picojson::parse(json_obj, metadata);
status->m_cget.reset();
if (!err.empty()) {
throw JsonException(err);
throw JsonException("JSON parse failure when downloading from the "
" public key URL " +
status->m_cget->get_url() + ": " + err);
}

auto now = std::time(NULL);
Expand Down
1 change: 1 addition & 0 deletions src/scitokens_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class SimpleCurlGet {
GetStatus perform_continue();
int perform(const std::string &url, time_t expiry_time);
void get_data(char *&buffer, size_t &len);
std::string get_url() const;

long get_timeout_ms() const { return m_timeout_ms; }
int get_max_fd() const { return m_max_fd; }
Expand Down

0 comments on commit 3d17d51

Please sign in to comment.