Skip to content

Commit

Permalink
fix: Ensure that a valid DSN has a public_key
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Oct 15, 2021
1 parent 90966cc commit 8bf632c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sentry_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ sentry__dsn_new(const char *raw_dsn)
*tmp = 0;
dsn->path = url.path;
url.path = NULL;
dsn->is_valid = true;

if (dsn->public_key && dsn->host && dsn->path) {
dsn->is_valid = true;
}

exit:
sentry__url_cleanup(&url);
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ SENTRY_TEST(dsn_parsing_complete)
TEST_CHECK_STRING_EQUAL(dsn->path, "/foo/bar");
TEST_CHECK_INT_EQUAL((int)dsn->project_id, 42);
sentry__dsn_decref(dsn);

dsn = sentry__dsn_new("https://username@example.com/42");
TEST_CHECK(!!dsn);
if (!dsn) {
return;
}
TEST_CHECK(dsn->is_valid);
TEST_CHECK(dsn->is_secure);
TEST_CHECK_STRING_EQUAL(dsn->host, "example.com");
TEST_CHECK_STRING_EQUAL(dsn->public_key, "username");
TEST_CHECK(!dsn->secret_key);
TEST_CHECK_STRING_EQUAL(dsn->path, "");
TEST_CHECK_INT_EQUAL((int)dsn->project_id, 42);
sentry__dsn_decref(dsn);
}

SENTRY_TEST(dsn_parsing_invalid)
Expand All @@ -105,6 +119,27 @@ SENTRY_TEST(dsn_parsing_invalid)
TEST_CHECK(!dsn->is_valid);
sentry__dsn_decref(dsn);
}

dsn = sentry__dsn_new("https://key@");
TEST_CHECK(!!dsn);
if (dsn) {
TEST_CHECK(!dsn->is_valid);
sentry__dsn_decref(dsn);
}

dsn = sentry__dsn_new("https://key@sentry.io");
TEST_CHECK(!!dsn);
if (dsn) {
TEST_CHECK(!dsn->is_valid);
sentry__dsn_decref(dsn);
}

dsn = sentry__dsn_new("https://sentry.io/1234567");
TEST_CHECK(!!dsn);
if (dsn) {
TEST_CHECK(!dsn->is_valid);
sentry__dsn_decref(dsn);
}
}

SENTRY_TEST(dsn_store_url_with_path)
Expand Down

0 comments on commit 8bf632c

Please sign in to comment.