forked from brave/brave-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_domains_unittest.cc
85 lines (64 loc) · 2.88 KB
/
service_domains_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#include "brave/brave_domains/service_domains.h"
#include <cstring>
#include "base/command_line.h"
#include "base/debug/debugging_buildflags.h"
#include "base/files/file_path.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/brave_domains/buildflags.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
namespace brave_domains {
namespace {
// Setup expected answers based on the buildflag values
const char kProductionValue[] = BUILDFLAG(BRAVE_SERVICES_PRODUCTION_DOMAIN);
const char kStagingValue[] = BUILDFLAG(BRAVE_SERVICES_STAGING_DOMAIN);
const char kDevValue[] = BUILDFLAG(BRAVE_SERVICES_DEV_DOMAIN);
} // namespace
TEST(BraveServiceDomains, TestValuesPresent) {
// These tests don't work if the values are the same, or empty
EXPECT_GT(strlen(kProductionValue), 0u);
EXPECT_GT(strlen(kStagingValue), 0u);
EXPECT_GT(strlen(kDevValue), 0u);
EXPECT_NE(kProductionValue, kStagingValue);
EXPECT_NE(kProductionValue, kDevValue);
EXPECT_NE(kStagingValue, kDevValue);
}
TEST(BraveServiceDomains, ProductionWhenEmpty) {
base::CommandLine cl(base::CommandLine::NO_PROGRAM);
EXPECT_EQ(GetServicesDomain("", &cl), kProductionValue);
}
TEST(BraveServiceDomains, GlobalStaging) {
base::CommandLine cl(base::CommandLine::NO_PROGRAM);
cl.AppendSwitchASCII("brave-services-env", "staging");
EXPECT_EQ(GetServicesDomain("", &cl), kStagingValue);
}
TEST(BraveServiceDomains, GlobalDev) {
base::CommandLine cl(base::CommandLine::NO_PROGRAM);
cl.AppendSwitchASCII("brave-services-env", "dev");
EXPECT_EQ(GetServicesDomain("", &cl), kDevValue);
}
TEST(BraveServiceDomains, PrefixOverride) {
std::string prefix = "my.sub.domain";
base::CommandLine cl(base::CommandLine::NO_PROGRAM);
cl.AppendSwitchASCII("brave-services-env", "dev");
cl.AppendSwitchASCII("env-my.sub.domain", "prod");
auto prefixed_domain = GetServicesDomain(prefix, &cl);
// Prefixed domain should be production override
EXPECT_TRUE(base::EndsWith(prefixed_domain, kProductionValue));
EXPECT_TRUE(base::StartsWith(prefixed_domain, prefix));
// All other domain retrievals should be dev
EXPECT_EQ(GetServicesDomain("", &cl), kDevValue);
std::string other_prefix = "another_prefix";
auto other_prefixed_domain = GetServicesDomain(other_prefix, &cl);
EXPECT_TRUE(base::EndsWith(other_prefixed_domain, kDevValue));
EXPECT_TRUE(base::StartsWith(other_prefixed_domain, other_prefix));
}
} // namespace brave_domains