Skip to content

Commit

Permalink
Fix issue with public keys when redeeming tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Mar 12, 2019
1 parent 0e43074 commit b09aa81
Show file tree
Hide file tree
Showing 21 changed files with 464 additions and 287 deletions.
2 changes: 2 additions & 0 deletions vendor/bat-native-confirmations/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ source_set("bat-native-confirmations") {
"src/bat/confirmations/internal/security_helper.h",
"src/bat/confirmations/internal/string_helper.cc",
"src/bat/confirmations/internal/string_helper.h",
"src/bat/confirmations/internal/token_info.cc",
"src/bat/confirmations/internal/token_info.h",
"src/bat/confirmations/internal/unblinded_tokens.cc",
"src/bat/confirmations/internal/unblinded_tokens.h",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class ConfirmationsCreateConfirmationRequestTest : public ::testing::Test {

TEST_F(ConfirmationsCreateConfirmationRequestTest, BuildUrl) {
// Arrange
std::string confirmation_id = "c7f8c42d-6768-4dd7-8dc6-612cbba3ec21";
std::string credential = "eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiQUZwNzMyaStXUU5lMUtGb0NJVFpMWkVDZmtYM0pHY3Fvc2lKbSt5KzRGTT1cIixcImNyZWF0aXZlSW5zdGFuY2VJZFwiOlwiNTg0MWE0NmUtNjBmMi00ZTAxLWFhMDAtYmEyMzZiZDEyY2NhXCIsXCJwYXlsb2FkXCI6e30sXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoienFyYzV1TlF5Mm12QS9RQ01XSDFyOHg3dEdDL1pBTFZJdno2M1ZXd3lRQy8zaDZTVWI2OXhEQmdPYTA3NmFJcUpGNDA3dVZ1TGM2bTFsSzFpUGxkM3c9PSIsInQiOiJPcnJjMlFkS0VRaERLRVk3NmNGRThqOVRreUIrbVBJV0h5TzhVcFErOGQraW5UblZnaWdidlZYYTd1TFJRWnRLdml1a2pQamdiYjk2THpwTVEzQzJHUT09In0="; // NOLINT
std::string confirmation_id = "d990ed8d-d739-49fb-811b-c2e02158fb60";
std::string credential = "eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiUEkzbEZxcEdWRkt6NFRINXlFd1hJM1IvUW50bVRwVWdlQmFLK1NUaUJ4OD1cIixcImNyZWF0aXZlSW5zdGFuY2VJZFwiOlwiNTQ2ZmU3YjAtNTA0Ny00ZjI4LWExMWMtODFmMTRlZGNmMGY2XCIsXCJwYXlsb2FkXCI6e30sXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoibGRWYWxyb2hqNWFIWW1FdWMvUmpIYTAweFdMdFJWY0hGMS9XWnl4ZGJYMnhkQ1ByMFgyMVg3cWtKVUxRdUw4U2JWWHJUT3lEbTJJNkFrT0R0SHYxR2c9PSIsInQiOiJQTG93ejJXRjJlR0Q1emZ3WmprOXA3NkhYQkxES01xLzNFQVpIZUcvZkUyWEdRNDhqeXRlK1ZlNTBabGFzT3VZTDVtd0E4Q1UyYUZNbEpydDNERGdDdz09In0="; // NOLINT

// Act
auto url = request_->BuildUrl(confirmation_id, credential);

// Assert
std::string expected_url = "https://ads-serve.bravesoftware.com/v1/confirmation/c7f8c42d-6768-4dd7-8dc6-612cbba3ec21/eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiQUZwNzMyaStXUU5lMUtGb0NJVFpMWkVDZmtYM0pHY3Fvc2lKbSt5KzRGTT1cIixcImNyZWF0aXZlSW5zdGFuY2VJZFwiOlwiNTg0MWE0NmUtNjBmMi00ZTAxLWFhMDAtYmEyMzZiZDEyY2NhXCIsXCJwYXlsb2FkXCI6e30sXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoienFyYzV1TlF5Mm12QS9RQ01XSDFyOHg3dEdDL1pBTFZJdno2M1ZXd3lRQy8zaDZTVWI2OXhEQmdPYTA3NmFJcUpGNDA3dVZ1TGM2bTFsSzFpUGxkM3c9PSIsInQiOiJPcnJjMlFkS0VRaERLRVk3NmNGRThqOVRreUIrbVBJV0h5TzhVcFErOGQraW5UblZnaWdidlZYYTd1TFJRWnRLdml1a2pQamdiYjk2THpwTVEzQzJHUT09In0="; // NOLINT
std::string expected_url = "https://ads-serve.bravesoftware.com/v1/confirmation/d990ed8d-d739-49fb-811b-c2e02158fb60/eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiUEkzbEZxcEdWRkt6NFRINXlFd1hJM1IvUW50bVRwVWdlQmFLK1NUaUJ4OD1cIixcImNyZWF0aXZlSW5zdGFuY2VJZFwiOlwiNTQ2ZmU3YjAtNTA0Ny00ZjI4LWExMWMtODFmMTRlZGNmMGY2XCIsXCJwYXlsb2FkXCI6e30sXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoibGRWYWxyb2hqNWFIWW1FdWMvUmpIYTAweFdMdFJWY0hGMS9XWnl4ZGJYMnhkQ1ByMFgyMVg3cWtKVUxRdUw4U2JWWHJUT3lEbTJJNkFrT0R0SHYxR2c9PSIsInQiOiJQTG93ejJXRjJlR0Q1emZ3WmprOXA3NkhYQkxES01xLzNFQVpIZUcvZkUyWEdRNDhqeXRlK1ZlNTBabGFzT3VZTDVtd0E4Q1UyYUZNbEpydDNERGdDdz09In0="; // NOLINT
EXPECT_EQ(expected_url, url);
}

Expand All @@ -80,10 +80,10 @@ TEST_F(ConfirmationsCreateConfirmationRequestTest, GetMethod) {

TEST_F(ConfirmationsCreateConfirmationRequestTest, BuildBody) {
// Arrange
std::string creative_instance_id = "465e08ad-03be-42ee-902a-dc88688aa2cb";
std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6";

std::string blinded_token_base64 =
"FvnSTMJ6dSeinPIdc3P2XQlv84Y1wcljzWmkfinVXHs=";
"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=";
auto blinded_token = BlindedToken::decode_base64(blinded_token_base64);

auto payload = request_->CreateConfirmationRequestDTO(creative_instance_id,
Expand All @@ -93,7 +93,7 @@ TEST_F(ConfirmationsCreateConfirmationRequestTest, BuildBody) {
auto body = request_->BuildBody(payload);

// Assert
std::string expected_body = R"({"blindedPaymentToken":"FvnSTMJ6dSeinPIdc3P2XQlv84Y1wcljzWmkfinVXHs=","creativeInstanceId":"465e08ad-03be-42ee-902a-dc88688aa2cb","payload":{},"type":"view"})"; // NOLINT
std::string expected_body = R"({"blindedPaymentToken":"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=","creativeInstanceId":"546fe7b0-5047-4f28-a11c-81f14edcf0f6","payload":{},"type":"view"})"; // NOLINT
EXPECT_EQ(expected_body, body);
}

Expand Down Expand Up @@ -131,40 +131,44 @@ TEST_F(ConfirmationsCreateConfirmationRequestTest, GetContentType) {
TEST_F(ConfirmationsCreateConfirmationRequestTest,
CreateConfirmationRequestDTO) {
// Arrange
std::string creative_instance_id = "465e08ad-03be-42ee-902a-dc88688aa2cb";
std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6";

std::string blinded_token_base64 =
"FvnSTMJ6dSeinPIdc3P2XQlv84Y1wcljzWmkfinVXHs=";
"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=";
auto blinded_token = BlindedToken::decode_base64(blinded_token_base64);

// Act
auto payload = request_->CreateConfirmationRequestDTO(creative_instance_id,
blinded_token);

// Assert
std::string expected_payload = R"({"blindedPaymentToken":"FvnSTMJ6dSeinPIdc3P2XQlv84Y1wcljzWmkfinVXHs=","creativeInstanceId":"465e08ad-03be-42ee-902a-dc88688aa2cb","payload":{},"type":"view"})"; // NOLINT
std::string expected_payload = R"({"blindedPaymentToken":"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=","creativeInstanceId":"546fe7b0-5047-4f28-a11c-81f14edcf0f6","payload":{},"type":"view"})"; // NOLINT
EXPECT_EQ(expected_payload, payload);
}

TEST_F(ConfirmationsCreateConfirmationRequestTest, CreateCredential) {
// Arrange
std::string unblinded_token_base64 = "Orrc2QdKEQhDKEY76cFE8j9TkyB+mPIWHyO8UpQ+8d+inTnVgigbvVXa7uLRQZtKviukjPjgbb96LzpMQ3C2GY7X7c2oL0nZiXeiGEsgkKYJWWDveLNCnT3zxpWJbFkR"; // NOLINT
auto unblinded_token = UnblindedToken::decode_base64(unblinded_token_base64);
std::string unblinded_token_base64 = "PLowz2WF2eGD5zfwZjk9p76HXBLDKMq/3EAZHeG/fE2XGQ48jyte+Ve50ZlasOuYL5mwA8CU2aFMlJrt3DDgC3B1+VD/uyHPfa/+bwYRrpVH5YwNSDEydVx8S4r+BYVY"; // NOLINT

std::string creative_instance_id = "5841a46e-60f2-4e01-aa00-ba236bd12cca";
TokenInfo token_info;
token_info.unblinded_token =
UnblindedToken::decode_base64(unblinded_token_base64);
token_info.public_key = "RJ2i/o/pZkrH+i0aGEMY1G9FXtd7Q7gfRi3YdNRnDDk=";

std::string creative_instance_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6";

std::string blinded_token_base64 =
"AFp732i+WQNe1KFoCITZLZECfkX3JGcqosiJm+y+4FM=";
"PI3lFqpGVFKz4TH5yEwXI3R/QntmTpUgeBaK+STiBx8=";
auto blinded_token = BlindedToken::decode_base64(blinded_token_base64);

auto payload = request_->CreateConfirmationRequestDTO(creative_instance_id,
blinded_token);

// Act
auto credential = request_->CreateCredential(unblinded_token, payload);
auto credential = request_->CreateCredential(token_info, payload);

// Assert
std::string expected_credential = "eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiQUZwNzMyaStXUU5lMUtGb0NJVFpMWkVDZmtYM0pHY3Fvc2lKbSt5KzRGTT1cIixcImNyZWF0aXZlSW5zdGFuY2VJZFwiOlwiNTg0MWE0NmUtNjBmMi00ZTAxLWFhMDAtYmEyMzZiZDEyY2NhXCIsXCJwYXlsb2FkXCI6e30sXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoienFyYzV1TlF5Mm12QS9RQ01XSDFyOHg3dEdDL1pBTFZJdno2M1ZXd3lRQy8zaDZTVWI2OXhEQmdPYTA3NmFJcUpGNDA3dVZ1TGM2bTFsSzFpUGxkM3c9PSIsInQiOiJPcnJjMlFkS0VRaERLRVk3NmNGRThqOVRreUIrbVBJV0h5TzhVcFErOGQraW5UblZnaWdidlZYYTd1TFJRWnRLdml1a2pQamdiYjk2THpwTVEzQzJHUT09In0="; // NOLINT
std::string expected_credential = "eyJwYXlsb2FkIjoie1wiYmxpbmRlZFBheW1lbnRUb2tlblwiOlwiUEkzbEZxcEdWRkt6NFRINXlFd1hJM1IvUW50bVRwVWdlQmFLK1NUaUJ4OD1cIixcImNyZWF0aXZlSW5zdGFuY2VJZFwiOlwiNTQ2ZmU3YjAtNTA0Ny00ZjI4LWExMWMtODFmMTRlZGNmMGY2XCIsXCJwYXlsb2FkXCI6e30sXCJ0eXBlXCI6XCJ2aWV3XCJ9Iiwic2lnbmF0dXJlIjoibGRWYWxyb2hqNWFIWW1FdWMvUmpIYTAweFdMdFJWY0hGMS9XWnl4ZGJYMnhkQ1ByMFgyMVg3cWtKVUxRdUw4U2JWWHJUT3lEbTJJNkFrT0R0SHYxR2c9PSIsInQiOiJQTG93ejJXRjJlR0Q1emZ3WmprOXA3NkhYQkxES01xLzNFQVpIZUcvZkUyWEdRNDhqeXRlK1ZlNTBabGFzT3VZTDVtd0E4Q1UyYUZNbEpydDNERGdDdz09In0="; // NOLINT
EXPECT_EQ(expected_credential, credential);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ class ConfirmationsFetchPaymentTokenRequestTest : public ::testing::Test {

TEST_F(ConfirmationsFetchPaymentTokenRequestTest, BuildUrl) {
// Arrange
std::string confirmation_id = "c7f8c42d-6768-4dd7-8dc6-612cbba3ec21";
std::string confirmation_id = "546fe7b0-5047-4f28-a11c-81f14edcf0f6";

// Act
auto url = request_->BuildUrl(confirmation_id);

// Assert
std::string expected_url = "https://ads-serve.bravesoftware.com/v1/confirmation/c7f8c42d-6768-4dd7-8dc6-612cbba3ec21/paymentToken"; // NOLINT
std::string expected_url = "https://ads-serve.bravesoftware.com/v1/confirmation/546fe7b0-5047-4f28-a11c-81f14edcf0f6/paymentToken"; // NOLINT
EXPECT_EQ(expected_url, url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ class ConfirmationsGetSignedTokensRequestTest : public ::testing::Test {
TEST_F(ConfirmationsGetSignedTokensRequestTest, BuildUrl) {
// Arrange
WalletInfo wallet_info;
wallet_info.payment_id = "e7fcf220-d3f4-4111-a0b2-6157d0347567";
wallet_info.public_key = "3fc8ff3b121e7b7875750d26eaba6f06a3b06d96cf6b2fb898323917e7be9d16e255a4a6f7eb8647428f727c0d4e1958bd8e69a984eee38514d1e483aab27edf"; // NOLINT
wallet_info.payment_id = "d4ed0af0-bfa9-464b-abd7-67b29d891b8b";
wallet_info.public_key = "e9b1ab4f44d39eb04323411eed0b5a2ceedff01264474f86e29c707a5661565033cea0085cfd551faa170c1dd7f6daaa903cdd3138d61ed5ab2845e224d58144"; // NOLINT

std::string nonce = "8561a644-6f42-49be-a2f4-4bc69dc87a27";
std::string nonce = "716c3381-66e6-46e4-962f-15d01455b5b9";

// Act
auto url = request_->BuildUrl(wallet_info, nonce);

// Assert
std::string expected_url = "https://ads-serve.bravesoftware.com/v1/confirmation/token/e7fcf220-d3f4-4111-a0b2-6157d0347567?nonce=8561a644-6f42-49be-a2f4-4bc69dc87a27"; // NOLINT
std::string expected_url = "https://ads-serve.bravesoftware.com/v1/confirmation/token/d4ed0af0-bfa9-464b-abd7-67b29d891b8b?nonce=716c3381-66e6-46e4-962f-15d01455b5b9"; // NOLINT
EXPECT_EQ(expected_url, url);
}

Expand Down
Loading

0 comments on commit b09aa81

Please sign in to comment.