#include "google_apis/gaia/oauth2_id_token_decoder.h"
#include <string>
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kIdTokenInvalidJwt[] =
"dummy-header."
"..."
".dummy-signature";
const char kIdTokenInvalidJson[] =
"dummy-header."
"YWJj"
".dummy-signature";
const char kIdTokenEmptyServices[] =
"dummy-header."
"eyAic2VydmljZXMiOiBbXSB9"
".dummy-signature";
const char kIdTokenEmptyServicesHeaderSignature[] =
"."
"eyAic2VydmljZXMiOiBbXSB9"
".";
const char kIdTokenMissingServices[] =
"dummy-header."
"eyAiYWJjIjogIiJ9"
".dummy-signature";
const char kIdTokenNotChildAccount[] =
"dummy-header."
"eyAic2VydmljZXMiOiBbImFiYyJdIH0="
".dummy-signature";
const char kIdTokenChildAccount[] =
"dummy-header."
"eyAic2VydmljZXMiOiBbInVjYSJdIH0="
".dummy-signature";
const char kIdTokenAdvancedProtectionAccount[] =
"dummy-header."
"eyAic2VydmljZXMiOiBbInRpYSJdIH0="
".dummy-signature";
const char kIdTokenChildAndAdvancedProtectionAccount[] =
"dummy-header."
"eyAic2VydmljZXMiOiBbInRpYSIsICJ1Y2EiXSB9"
".dummy-signature";
class OAuth2IdTokenDecoderTest : public testing::Test {};
TEST_F(OAuth2IdTokenDecoderTest, Invalid) {
EXPECT_FALSE(gaia::ParseServiceFlags(kIdTokenInvalidJwt).is_child_account);
EXPECT_FALSE(gaia::ParseServiceFlags(kIdTokenInvalidJson).is_child_account);
EXPECT_FALSE(
gaia::ParseServiceFlags(kIdTokenMissingServices).is_child_account);
}
TEST_F(OAuth2IdTokenDecoderTest, NotChild) {
EXPECT_FALSE(gaia::ParseServiceFlags(kIdTokenEmptyServices).is_child_account);
EXPECT_FALSE(gaia::ParseServiceFlags(kIdTokenEmptyServicesHeaderSignature)
.is_child_account);
EXPECT_FALSE(
gaia::ParseServiceFlags(kIdTokenNotChildAccount).is_child_account);
}
TEST_F(OAuth2IdTokenDecoderTest, Child) {
EXPECT_TRUE(gaia::ParseServiceFlags(kIdTokenChildAccount).is_child_account);
}
TEST_F(OAuth2IdTokenDecoderTest, NotAdvancedProtection) {
EXPECT_FALSE(gaia::ParseServiceFlags(kIdTokenEmptyServices)
.is_under_advanced_protection);
EXPECT_FALSE(gaia::ParseServiceFlags(kIdTokenEmptyServicesHeaderSignature)
.is_under_advanced_protection);
EXPECT_FALSE(gaia::ParseServiceFlags(kIdTokenChildAccount)
.is_under_advanced_protection);
}
TEST_F(OAuth2IdTokenDecoderTest, AdvancedProtection) {
EXPECT_TRUE(gaia::ParseServiceFlags(kIdTokenAdvancedProtectionAccount)
.is_under_advanced_protection);
gaia::TokenServiceFlags service_flags =
gaia::ParseServiceFlags(kIdTokenChildAndAdvancedProtectionAccount);
EXPECT_TRUE(service_flags.is_child_account);
EXPECT_TRUE(service_flags.is_under_advanced_protection);
}
}