OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "auth_data.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace authentication { |
| 10 namespace { |
| 11 |
| 12 AuthData* GetInputData() { |
| 13 AuthData* auth_data = new AuthData(); |
| 14 |
| 15 auth_data->username = "test@google.com"; |
| 16 auth_data->auth_provider = "Google"; |
| 17 auth_data->persistent_credential_type = "RT"; |
| 18 auth_data->persistent_credential = "test_refresh_token"; |
| 19 auth_data->scopes = "profile email"; |
| 20 |
| 21 return auth_data; |
| 22 } |
| 23 |
| 24 std::string GetInputString(AuthData* auth_data) { |
| 25 std::string expected_str; |
| 26 expected_str += auth_data->username + ","; |
| 27 expected_str += auth_data->auth_provider + ","; |
| 28 expected_str += auth_data->persistent_credential_type + ","; |
| 29 expected_str += auth_data->persistent_credential + ","; |
| 30 expected_str += auth_data->scopes; |
| 31 |
| 32 return expected_str; |
| 33 } |
| 34 |
| 35 TEST(AuthDataTest, ConvertToString) { |
| 36 AuthData* auth_data = GetInputData(); |
| 37 |
| 38 std::string auth_data_str(authentication::GetAuthDataAsString(*auth_data)); |
| 39 EXPECT_EQ(auth_data_str.size(), GetInputString(auth_data).size()); |
| 40 EXPECT_TRUE(auth_data_str.find(auth_data->username) != std::string::npos); |
| 41 EXPECT_TRUE(auth_data_str.find(auth_data->scopes) != std::string::npos); |
| 42 } |
| 43 |
| 44 TEST(AuthDataTest, ParseFromString) { |
| 45 AuthData* auth_data = GetInputData(); |
| 46 AuthData* out = |
| 47 authentication::GetAuthDataFromString(GetInputString(auth_data)); |
| 48 |
| 49 EXPECT_EQ(auth_data->username, out->username); |
| 50 EXPECT_EQ(auth_data->auth_provider, out->auth_provider); |
| 51 EXPECT_EQ(auth_data->persistent_credential_type, |
| 52 out->persistent_credential_type); |
| 53 EXPECT_EQ(auth_data->persistent_credential, out->persistent_credential); |
| 54 EXPECT_EQ(auth_data->scopes, out->scopes); |
| 55 } |
| 56 |
| 57 TEST(AuthDataTest, InvalidInput) { |
| 58 std::string empty_auth_data_str; |
| 59 AuthData* out = authentication::GetAuthDataFromString(empty_auth_data_str); |
| 60 EXPECT_TRUE(out == nullptr); |
| 61 |
| 62 std::string auth_data_str_missing_components("a:b:c"); |
| 63 out = authentication::GetAuthDataFromString(auth_data_str_missing_components); |
| 64 EXPECT_TRUE(out == nullptr); |
| 65 |
| 66 std::string invalid_auth_data_str("a:b:c:d:e:f"); |
| 67 out = authentication::GetAuthDataFromString(invalid_auth_data_str); |
| 68 EXPECT_TRUE(out == nullptr); |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 } // namespace authentication |
OLD | NEW |