Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Features**:

- Add runtime API to query user consent requirement ([#1443](https://github.com/getsentry/sentry-native/pull/1443))

## 0.12.1

**Fixes**:
Expand Down
10 changes: 10 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,16 @@ SENTRY_API void sentry_user_consent_reset(void);
*/
SENTRY_API sentry_user_consent_t sentry_user_consent_get(void);

/**
* Checks whether user consent is required.
*
* This returns the value that was configured via
* `sentry_options_set_require_user_consent` during initialization.
*
* Returns 1 if user consent is required, 0 otherwise.
*/
SENTRY_API int sentry_user_consent_is_required(void);

/**
* A sentry Scope.
*
Expand Down
10 changes: 10 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ sentry_user_consent_get(void)
return rv;
}

int
Copy link
Contributor

Choose a reason for hiding this comment

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

int needed or we could use bool here? require_user_consent is a boolean.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The existing public API uses int for similar boolean-style returns so the idea was just to keep it consistent.

sentry_user_consent_is_required(void)
{
int required = 0;
SENTRY_WITH_OPTIONS (options) {
required = options->require_user_consent;
}
return required;
}

void
sentry__capture_envelope(
sentry_transport_t *transport, sentry_envelope_t *envelope)
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/test_consent.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ init_consenting_sentry(void)
sentry_init(opts);
}

static void
init_not_consenting_sentry(void)
{
sentry_options_t *opts = sentry_options_new();
sentry_options_set_database_path(opts, SENTRY_TEST_PATH_PREFIX ".test-db");
sentry_options_set_dsn(opts, "http://[email protected]/42");
sentry_options_set_require_user_consent(opts, false);
sentry_init(opts);
}

SENTRY_TEST(basic_consent_tracking)
{
sentry_path_t *path
Expand Down Expand Up @@ -54,3 +64,32 @@ SENTRY_TEST(basic_consent_tracking)
sentry__path_remove_all(path);
sentry__path_free(path);
}

SENTRY_TEST(query_consent_requirement)
{
sentry_path_t *path
= sentry__path_from_str(SENTRY_TEST_PATH_PREFIX ".test-db");
TEST_ASSERT(!!path);
sentry__path_remove_all(path);

// Test default behavior when require_user_consent is not set
sentry_options_t *opts = sentry_options_new();
sentry_options_set_database_path(opts, SENTRY_TEST_PATH_PREFIX ".test-db");
sentry_options_set_dsn(opts, "http://[email protected]/42");
sentry_init(opts);
TEST_CHECK_INT_EQUAL(sentry_user_consent_is_required(), 0);
sentry_close();

// Test when consent is explicitly NOT required
init_not_consenting_sentry();
TEST_CHECK_INT_EQUAL(sentry_user_consent_is_required(), 0);
sentry_close();

// Test when consent IS required
init_consenting_sentry();
TEST_CHECK_INT_EQUAL(sentry_user_consent_is_required(), 1);
sentry_close();

sentry__path_remove_all(path);
sentry__path_free(path);
}
1 change: 1 addition & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ XX(attachments_bytes)
XX(attachments_extend)
XX(background_worker)
XX(basic_consent_tracking)
XX(query_consent_requirement)
XX(basic_function_transport)
XX(basic_function_transport_transaction)
XX(basic_function_transport_transaction_ts)
Expand Down
Loading