OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/host/setup/oauth_helper.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace { | |
12 | |
13 std::string Replace(const std::string& s, const std::string& old_substr, | |
14 const std::string& new_substr) { | |
15 size_t pos = s.find(old_substr); | |
16 if (pos == std::string::npos) { | |
17 return s; | |
18 } | |
19 return s.substr(0, pos) + new_substr + | |
20 s.substr(pos + old_substr.length(), std::string::npos); | |
21 } | |
22 | |
23 std::string GetTestRedirectUrl() { | |
24 return std::string("https://google.com/redirect"); | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 namespace remoting { | |
30 | |
31 TEST(OauthHelperTest, TestNotCode) { | |
32 ASSERT_EQ("", GetOauthCodeInUrl("notURL", GetTestRedirectUrl())); | |
33 } | |
34 | |
35 TEST(OauthHelperTest, TestVeryShort) { | |
36 ASSERT_EQ("", GetOauthCodeInUrl(GetTestRedirectUrl(), GetTestRedirectUrl())); | |
37 } | |
38 | |
39 TEST(OauthHelperTest, TestEmptyQuery) { | |
40 ASSERT_EQ("", GetOauthCodeInUrl(GetTestRedirectUrl() + "?", | |
41 GetTestRedirectUrl())); | |
42 } | |
43 | |
44 TEST(OauthHelperTest, TestNoQueryValue) { | |
45 ASSERT_EQ("", GetOauthCodeInUrl(GetTestRedirectUrl() + "?code", | |
46 GetTestRedirectUrl())); | |
47 } | |
48 | |
49 TEST(OauthHelperTest, TestEmptyCode) { | |
50 ASSERT_EQ("", GetOauthCodeInUrl(GetTestRedirectUrl() + "?code=", | |
51 GetTestRedirectUrl())); | |
52 } | |
53 | |
54 TEST(OauthHelperTest, TestCode) { | |
55 ASSERT_EQ("Dummy", GetOauthCodeInUrl(GetTestRedirectUrl() + "?code=Dummy", | |
56 GetTestRedirectUrl())); | |
57 } | |
58 | |
59 TEST(OauthHelperTest, TestCodeInLongQuery) { | |
60 ASSERT_EQ("Dummy", GetOauthCodeInUrl(GetTestRedirectUrl() + | |
61 "?x=1&code=Dummy&y=2", | |
62 GetTestRedirectUrl())); | |
63 } | |
64 | |
65 TEST(OauthHelperTest, TestBadScheme) { | |
66 std::string url = GetTestRedirectUrl() + "?code=Dummy"; | |
67 url = Replace(url, "https:", "http"); | |
68 ASSERT_EQ("", GetOauthCodeInUrl(url, GetTestRedirectUrl())); | |
69 } | |
70 | |
71 TEST(OauthHelperTest, TestBadHost) { | |
72 std::string url = GetTestRedirectUrl() + "?code=Dummy"; | |
73 url = Replace(url, "google", "goggle"); | |
74 ASSERT_EQ("", GetOauthCodeInUrl(url, GetTestRedirectUrl())); | |
75 } | |
76 | |
77 } // namespace remoting | |
OLD | NEW |