Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: google_apis/gaia/gaia_auth_util_unittest.cc

Issue 1162103003: ListAccounts will return the Gaia ID as well as the email of the account. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « google_apis/gaia/gaia_auth_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/gaia/gaia_auth_util.h" 5 #include "google_apis/gaia/gaia_auth_util.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 namespace gaia { 10 namespace gaia {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.google.com/"))); 102 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.google.com/")));
103 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/"))); 103 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/")));
104 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/"))); 104 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/")));
105 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/"))); 105 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/")));
106 106
107 // Other https URLs are not valid. 107 // Other https URLs are not valid.
108 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/"))); 108 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/")));
109 } 109 }
110 110
111 TEST(GaiaAuthUtilTest, ParseListAccountsData) { 111 TEST(GaiaAuthUtilTest, ParseListAccountsData) {
112 std::vector<std::pair<std::string, bool> > accounts; 112 std::vector<ListedAccount> accounts;
113 ASSERT_FALSE(ParseListAccountsData("", &accounts)); 113 ASSERT_FALSE(ParseListAccountsData("", &accounts));
114 ASSERT_EQ(0u, accounts.size()); 114 ASSERT_EQ(0u, accounts.size());
115 115
116 ASSERT_FALSE(ParseListAccountsData("1", &accounts)); 116 ASSERT_FALSE(ParseListAccountsData("1", &accounts));
117 ASSERT_EQ(0u, accounts.size()); 117 ASSERT_EQ(0u, accounts.size());
118 118
119 ASSERT_FALSE(ParseListAccountsData("[]", &accounts)); 119 ASSERT_FALSE(ParseListAccountsData("[]", &accounts));
120 ASSERT_EQ(0u, accounts.size()); 120 ASSERT_EQ(0u, accounts.size());
121 121
122 ASSERT_FALSE(ParseListAccountsData("[\"foo\", \"bar\"]", &accounts)); 122 ASSERT_FALSE(ParseListAccountsData("[\"foo\", \"bar\"]", &accounts));
123 ASSERT_EQ(0u, accounts.size()); 123 ASSERT_EQ(0u, accounts.size());
124 124
125 ASSERT_TRUE(ParseListAccountsData("[\"foo\", []]", &accounts)); 125 ASSERT_TRUE(ParseListAccountsData("[\"foo\", []]", &accounts));
126 ASSERT_EQ(0u, accounts.size()); 126 ASSERT_EQ(0u, accounts.size());
127 127
128 ASSERT_TRUE(ParseListAccountsData( 128 ASSERT_TRUE(ParseListAccountsData(
129 "[\"foo\", [[\"bar\", 0, \"name\", 0, \"photo\", 0, 0, 0]]]", &accounts)); 129 "[\"foo\", [[\"bar\", 0, \"name\", 0, \"photo\", 0, 0, 0]]]", &accounts));
130 ASSERT_EQ(0u, accounts.size()); 130 ASSERT_EQ(0u, accounts.size());
131 131
132 ASSERT_TRUE(ParseListAccountsData( 132 ASSERT_TRUE(ParseListAccountsData(
133 "[\"foo\", [[\"bar\", 0, \"name\", \"u@g.c\", \"photo\", 0, 0, 0]]]", 133 "[\"foo\", "
134 "[[\"bar\", 0, \"name\", \"u@g.c\", \"p\", 0, 0, 0, 0, 1, \"45\"]]]",
134 &accounts)); 135 &accounts));
135 ASSERT_EQ(1u, accounts.size()); 136 ASSERT_EQ(1u, accounts.size());
136 ASSERT_EQ("u@g.c", accounts[0].first); 137 ASSERT_EQ("u@g.c", accounts[0].email);
137 ASSERT_TRUE(accounts[0].second); 138 ASSERT_TRUE(accounts[0].valid);
138 139
139 ASSERT_TRUE(ParseListAccountsData( 140 ASSERT_TRUE(ParseListAccountsData(
140 "[\"foo\", [[\"bar1\", 0, \"name1\", \"u1@g.c\", \"photo1\", 0, 0, 0], " 141 "[\"foo\", "
141 "[\"bar2\", 0, \"name2\", \"u2@g.c\", \"photo2\", 0, 0, 0]]]", 142 "[[\"bar1\",0,\"name1\",\"u1@g.c\",\"photo1\",0,0,0,0,1,\"45\"], "
143 "[\"bar2\",0,\"name2\",\"u2@g.c\",\"photo2\",0,0,0,0,1,\"6\"]]]",
142 &accounts)); 144 &accounts));
143 ASSERT_EQ(2u, accounts.size()); 145 ASSERT_EQ(2u, accounts.size());
144 ASSERT_EQ("u1@g.c", accounts[0].first); 146 ASSERT_EQ("u1@g.c", accounts[0].email);
145 ASSERT_TRUE(accounts[0].second); 147 ASSERT_TRUE(accounts[0].valid);
146 ASSERT_EQ("u2@g.c", accounts[1].first); 148 ASSERT_EQ("u2@g.c", accounts[1].email);
147 ASSERT_TRUE(accounts[1].second); 149 ASSERT_TRUE(accounts[1].valid);
148 150
149 ASSERT_TRUE(ParseListAccountsData( 151 ASSERT_TRUE(ParseListAccountsData(
150 "[\"foo\", [[\"b1\", 0, \"name1\", \"U1@g.c\", \"photo1\", 0, 0, 0], " 152 "[\"foo\", "
151 "[\"b2\", 0, \"name2\", \"u.2@g.c\", \"photo2\", 0, 0, 0]]]", 153 "[[\"b1\", 0,\"name1\",\"U1@g.c\",\"photo1\",0,0,0,0,1,\"45\"], "
154 "[\"b2\",0,\"name2\",\"u.2@g.c\",\"photo2\",0,0,0,0,1,\"46\"]]]",
152 &accounts)); 155 &accounts));
153 ASSERT_EQ(2u, accounts.size()); 156 ASSERT_EQ(2u, accounts.size());
154 ASSERT_EQ(CanonicalizeEmail("U1@g.c"), accounts[0].first); 157 ASSERT_EQ(CanonicalizeEmail("U1@g.c"), accounts[0].email);
155 ASSERT_TRUE(accounts[0].second); 158 ASSERT_TRUE(accounts[0].valid);
156 ASSERT_EQ(CanonicalizeEmail("u.2@g.c"), accounts[1].first); 159 ASSERT_EQ(CanonicalizeEmail("u.2@g.c"), accounts[1].email);
157 ASSERT_TRUE(accounts[1].second); 160 ASSERT_TRUE(accounts[1].valid);
158 } 161 }
159 162
160 TEST(GaiaAuthUtilTest, ParseListAccountsDataValidSession) { 163 TEST(GaiaAuthUtilTest, ParseListAccountsDataValidSession) {
161 std::vector<std::pair<std::string, bool> > accounts; 164 std::vector<ListedAccount> accounts;
162
163 // Missing valid session means: return account.
164 ASSERT_TRUE(ParseListAccountsData(
165 "[\"foo\", [[\"b\", 0, \"n\", \"u@g.c\", \"p\", 0, 0, 0]]]",
166 &accounts));
167 ASSERT_EQ(1u, accounts.size());
168 ASSERT_EQ("u@g.c", accounts[0].first);
169 ASSERT_TRUE(accounts[0].second);
170 165
171 // Valid session is true means: return account. 166 // Valid session is true means: return account.
172 ASSERT_TRUE(ParseListAccountsData( 167 ASSERT_TRUE(ParseListAccountsData(
173 "[\"foo\", [[\"b\", 0, \"n\", \"u@g.c\", \"p\", 0, 0, 0, 0, 1]]]", 168 "[\"foo\", [[\"b\",0,\"n\",\"u@g.c\",\"photo\",0,0,0,0,1,\"45\"]]]",
174 &accounts)); 169 &accounts));
175 ASSERT_EQ(1u, accounts.size()); 170 ASSERT_EQ(1u, accounts.size());
176 ASSERT_EQ("u@g.c", accounts[0].first); 171 ASSERT_EQ("u@g.c", accounts[0].email);
177 ASSERT_TRUE(accounts[0].second); 172 ASSERT_TRUE(accounts[0].valid);
178 173
179 // Valid session is false means: return account with valid bit false. 174 // Valid session is false means: return account with valid bit false.
180 ASSERT_TRUE(ParseListAccountsData( 175 ASSERT_TRUE(ParseListAccountsData(
181 "[\"foo\", [[\"b\", 0, \"n\", \"u@g.c\", \"p\", 0, 0, 0, 0, 0]]]", 176 "[\"foo\", [[\"b\",0,\"n\",\"u@g.c\",\"photo\",0,0,0,0,0,\"45\"]]]",
182 &accounts)); 177 &accounts));
183 ASSERT_EQ(1u, accounts.size()); 178 ASSERT_EQ(1u, accounts.size());
184 ASSERT_FALSE(accounts[0].second); 179 ASSERT_FALSE(accounts[0].valid);
180 }
181
182 TEST(GaiaAuthUtilTest, ParseListAccountsDataGaiaId) {
183 std::vector<ListedAccount> accounts;
184
185 // Missing gaia id means: do not return account.
186 ASSERT_TRUE(ParseListAccountsData(
187 "[\"foo\", [[\"b\", 0, \"n\", \"u@g.c\", \"photo\", 0, 0, 0, 0, 1]]]",
188 &accounts));
189 ASSERT_EQ(0u, accounts.size());
190
191 // Valid gaia session means: return gaia session
192 ASSERT_TRUE(ParseListAccountsData(
193 "[\"foo\", "
194 "[[\"b\",0,\"n\",\"u@g.c\",\"photo\",0,0,0,0,1,\"9863\"]]]",
195 &accounts));
196 ASSERT_EQ(1u, accounts.size());
197 ASSERT_EQ("u@g.c", accounts[0].email);
198 ASSERT_TRUE(accounts[0].valid);
199 ASSERT_EQ("9863", accounts[0].gaia_id);
185 } 200 }
186 201
187 } // namespace gaia 202 } // namespace gaia
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_auth_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698