Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / api / cast_channel / cast_auth_ica_unittest.cc
blob900524257f6da804d4b7459ab5a9c0626997ebf8
1 // Copyright 2014 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.
5 #include "extensions/browser/api/cast_channel/cast_auth_ica.h"
7 #include <string>
9 #include "base/base64.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace extensions {
14 namespace api {
16 namespace cast_channel {
18 namespace {
20 static const net::SHA256HashValue kFingerprintValid1 = {{
21 0x52, 0x9D, 0x9C, 0xD6, 0x7F, 0xE5, 0xEB, 0x69, 0x8E, 0x70, 0xDD, 0x26,
22 0xD7, 0xD8, 0xF1, 0x26, 0x59, 0xF1, 0xE6, 0xE5, 0x23, 0x48, 0xBF, 0x6A,
23 0x5C, 0xF7, 0x16, 0xE1, 0x3F, 0x41, 0x0E, 0x73
24 }};
26 static const net::SHA256HashValue kFingerprintValid2 = {{
27 0xA2, 0x48, 0xC2, 0xE8, 0x54, 0xE6, 0x56, 0xA5, 0x6D, 0xE8, 0x23, 0x1F,
28 0x1E, 0xE1, 0x75, 0x6F, 0xDB, 0xE4, 0x07, 0xF9, 0xFE, 0xD4, 0x65, 0x0D,
29 0x60, 0xCC, 0x5A, 0xCB, 0x65, 0x11, 0xC7, 0x20
30 }};
32 static const net::SHA256HashValue kFingerprintInvalid = {{
33 0x00, 0x9D, 0x9C, 0xD6, 0x7F, 0xE5, 0xEB, 0x69, 0x8E, 0x70, 0xDD, 0x26,
34 0xD7, 0xD8, 0xF1, 0x26, 0x59, 0xF1, 0xE6, 0xE5, 0x23, 0x48, 0xBF, 0x6A,
35 0x5C, 0xF7, 0x16, 0xE1, 0x3F, 0x41, 0x0E, 0x73
36 }};
38 } // namespace
40 class CastChannelAuthorityKeysTest : public testing::Test {
41 public:
42 CastChannelAuthorityKeysTest() {}
43 ~CastChannelAuthorityKeysTest() override {}
45 protected:
46 void ExpectKeysLoaded();
47 AuthorityKeyStore authority_keys_store_;
50 void CastChannelAuthorityKeysTest::ExpectKeysLoaded() {
51 base::StringPiece key = authority_keys_store_.GetDefaultICAPublicKey();
52 EXPECT_FALSE(key.empty());
54 key =
55 authority_keys_store_.GetICAPublicKeyFromFingerprint(kFingerprintValid1);
56 EXPECT_FALSE(key.empty());
58 key =
59 authority_keys_store_.GetICAPublicKeyFromFingerprint(kFingerprintInvalid);
60 EXPECT_TRUE(key.empty());
63 TEST_F(CastChannelAuthorityKeysTest, TestDefaultKeys) {
64 base::StringPiece key = authority_keys_store_.GetDefaultICAPublicKey();
65 EXPECT_TRUE(key.empty());
68 TEST_F(CastChannelAuthorityKeysTest, TestInvalidProtobuf) {
69 std::string keys = "test";
70 EXPECT_EQ(authority_keys_store_.Load(keys), false);
72 base::StringPiece key = authority_keys_store_.GetDefaultICAPublicKey();
73 EXPECT_TRUE(key.empty());
76 TEST_F(CastChannelAuthorityKeysTest, TestValidProtobuf) {
77 std::string keys =
78 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
79 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
80 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
81 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
82 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
83 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQqzAgog"
84 "okjC6FTmVqVt6CMfHuF1b9vkB/n+1GUNYMxay2URxyASjgIwggEKAoIBAQCwDl4HOt+kX2"
85 "j3Icdk27Z27+6Lk/j2G4jhk7cX8BUeflJVdzwCjXtKbNO91sGccsizFc8RwfVGxNUgR/sw"
86 "9ORhDGjwXqs3jpvhvIHDcIp41oM0MpwZYuvknO3jZGxBHZzSi0hMI5CVs+dS6gVXzGCzuh"
87 "TkugA55EZVdM5ajnpnI9poCvrEhB60xaGianMfbsguL5qeqLEO/Yemj009SwXVNVp0TbyO"
88 "gkSW9LWVYE6l3yc9QVwHo7Q1WrOe8gUkys0xWg0mTNTT/VDhNOlMgVgwssd63YGJptQ6OI"
89 "QDtzSedz//eAdbmcGyHzVWbjo8DCXhV/aKfknAzIMRNeeRbS5lAgMBAAE=";
91 std::string decoded_keys;
92 EXPECT_EQ(base::Base64Decode(keys, &decoded_keys), true);
93 EXPECT_EQ(authority_keys_store_.Load(decoded_keys), true);
95 ExpectKeysLoaded();
97 base::StringPiece key =
98 authority_keys_store_.GetICAPublicKeyFromFingerprint(kFingerprintValid2);
99 EXPECT_FALSE(key.empty());
102 TEST_F(CastChannelAuthorityKeysTest, TestSetTrustedCertificateAuthorities) {
103 std::string keys =
104 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
105 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
106 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
107 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
108 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
109 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQ==";
110 std::string signature =
111 "chCUHZKkykcwU8HzU+hm027fUTBL0dqPMtrzppwExQwK9+"
112 "XlmCjJswfce2sUUfhR1OL1tyW4hWFwu4JnuQCJ+CvmSmAh2bzRpnuSKzBfgvIDjNOAGUs7"
113 "ADaNSSWPLxp+6ko++2Dn4S9HpOt8N1v6gMWqj3Ru5IqFSQPZSvGH2ois6uE50CFayPcjQE"
114 "OVZt41noQdFd15RmKTvocoCC5tHNlaikeQ52yi0IScOlad1B1lMhoplW3rWophQaqxMumr"
115 "OcHIZ+Y+p858x5f8Pny/kuqUClmFh9B/vF07NsUHwoSL9tA5t5jCY3L5iUc/v7o3oFcW/T"
116 "gojKkX2Kg7KQ86QA==";
117 EXPECT_FALSE(SetTrustedCertificateAuthorities(keys, "signature"));
118 EXPECT_FALSE(SetTrustedCertificateAuthorities("keys", signature));
119 EXPECT_FALSE(SetTrustedCertificateAuthorities(keys, signature));
120 EXPECT_FALSE(SetTrustedCertificateAuthorities(std::string(), std::string()));
122 keys =
123 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
124 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
125 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
126 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
127 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
128 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQqzAgog"
129 "okjC6FTmVqVt6CMfHuF1b9vkB/n+1GUNYMxay2URxyASjgIwggEKAoIBAQCwDl4HOt+kX2"
130 "j3Icdk27Z27+6Lk/j2G4jhk7cX8BUeflJVdzwCjXtKbNO91sGccsizFc8RwfVGxNUgR/sw"
131 "9ORhDGjwXqs3jpvhvIHDcIp41oM0MpwZYuvknO3jZGxBHZzSi0hMI5CVs+dS6gVXzGCzuh"
132 "TkugA55EZVdM5ajnpnI9poCvrEhB60xaGianMfbsguL5qeqLEO/Yemj009SwXVNVp0TbyO"
133 "gkSW9LWVYE6l3yc9QVwHo7Q1WrOe8gUkys0xWg0mTNTT/VDhNOlMgVgwssd63YGJptQ6OI"
134 "QDtzSedz//eAdbmcGyHzVWbjo8DCXhV/aKfknAzIMRNeeRbS5lAgMBAAE=";
135 signature =
136 "o83oku3jP+xjTysNBalqp/ZfJRPLt8R+IUhZMepbARFSRVizLoeFW5XyUwe6lQaC+PFFQH"
137 "SZeGZyeeGRpwCJ/lef0xh6SWJlVMWNTk5+z0U84GQdizJP/CTCeHpIwMobN+kyDajgOyfD"
138 "DLhktc6LHmSlFGG6J7B8W67oziS8ZFEdrcT9WSXFrjLVyURHjvidZD5iFtuImI6k9R9OoX"
139 "LR6SyAwpjdrL+vlHMk3Gol6KQ98YpF0ghHnN3/FFW4ibvIwjmRbp+tUV3h8TRcCOjlXVGp"
140 "bzPtNRRlTqfv7Rxm5YXkZMLmJJMZiTs5+o8FMRMTQZT4hRR3DQ+A/jofViyTGA==";
141 EXPECT_TRUE(SetTrustedCertificateAuthorities(keys, signature));
143 base::StringPiece result = GetDefaultTrustedICAPublicKey();
144 EXPECT_FALSE(result.empty());
147 } // namespace cast_channel
149 } // namespace api
151 } // namespace extensions