Roll WebRTC 9933:9992, Libjingle 9934:9991
[chromium-blink-merge.git] / chromecast / crypto / signature_cache_unittest.cc
blob3a7aa5b4d5f2cfb93329e57d8debf324aa56c1ed
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.
5 #include "chromecast/crypto/signature_cache.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 namespace chromecast {
9 namespace {
11 TEST(SignatureCache, Hit) {
12 const std::string private_key1("key1");
13 const std::string hash1("hash1");
14 const std::string hash2("hash2");
15 const std::string signature1("signature1");
16 const std::string signature2("signature2");
17 SignatureCache cache;
18 cache.Put(private_key1, hash1, signature1);
19 cache.Put(private_key1, hash2, signature2);
20 ASSERT_EQ(signature1, cache.Get(private_key1, hash1));
21 ASSERT_EQ(signature2, cache.Get(private_key1, hash2));
24 TEST(SignatureCache, Miss) {
25 const std::string private_key1("key1");
26 const std::string hash1("hash1");
27 const std::string hash2("hash2");
28 const std::string signature1("signature1");
29 SignatureCache cache;
30 cache.Put(private_key1, hash1, signature1);
31 ASSERT_EQ("", cache.Get(private_key1, hash2));
34 TEST(SignatureCache, NewPrivateKeyHit) {
35 const std::string private_key1("key1");
36 const std::string private_key2("key2");
37 const std::string hash1("hash1");
38 const std::string signature1("signature1");
39 SignatureCache cache;
40 cache.Put(private_key1, hash1, signature1);
41 cache.Put(private_key2, hash1, signature1);
42 ASSERT_EQ(signature1, cache.Get(private_key2, hash1));
45 TEST(SignatureCache, NewPrivateKeyMiss) {
46 const std::string private_key1("key1");
47 const std::string private_key2("key2");
48 const std::string hash1("hash1");
49 const std::string signature1("signature1");
50 SignatureCache cache;
51 cache.Put(private_key1, hash1, signature1);
52 ASSERT_EQ("", cache.Get(private_key2, hash1));
53 cache.Put(private_key2, hash1, signature1);
54 ASSERT_NE(signature1, cache.Get(private_key1, hash1));
57 } // namespace
58 } // namespace chromecast