Files
Armin Ronacher 6d6d49373b feat: Add user consent tracking (#116)
This adds basic user consent tracking. When enabled user consent is required
for event sending otherwise the event is silently dropped.
2019-12-19 15:09:26 +01:00

47 lines
1.4 KiB
C++

#include <sentry.h>
#include <path.hpp>
#include <vendor/catch.hpp>
static void init_consenting_sentry() {
#ifdef __ANDROID__
#define PREFIX "/data/local/tmp/"
#else
#define PREFIX ""
#endif
sentry_options_t *opts = sentry_options_new();
sentry_options_set_database_path(opts, PREFIX ".test-db");
sentry_options_set_dsn(opts, "http://foo@127.0.0.1/42");
sentry_options_set_require_user_consent(opts, true);
sentry_init(opts);
}
TEST_CASE("basic consent tracking", "[api]") {
sentry::Path(PREFIX ".test-db").remove_all();
init_consenting_sentry();
REQUIRE(sentry_user_consent_get() == SENTRY_USER_CONSENT_UNKNOWN);
sentry_shutdown();
init_consenting_sentry();
sentry_user_consent_give();
REQUIRE(sentry_user_consent_get() == SENTRY_USER_CONSENT_GIVEN);
sentry_shutdown();
init_consenting_sentry();
REQUIRE(sentry_user_consent_get() == SENTRY_USER_CONSENT_GIVEN);
sentry_user_consent_revoke();
REQUIRE(sentry_user_consent_get() == SENTRY_USER_CONSENT_REVOKED);
sentry_shutdown();
init_consenting_sentry();
REQUIRE(sentry_user_consent_get() == SENTRY_USER_CONSENT_REVOKED);
sentry_user_consent_reset();
REQUIRE(sentry_user_consent_get() == SENTRY_USER_CONSENT_UNKNOWN);
sentry_shutdown();
init_consenting_sentry();
REQUIRE(sentry_user_consent_get() == SENTRY_USER_CONSENT_UNKNOWN);
sentry_shutdown();
sentry::Path(PREFIX ".test-db").remove_all();
}