ssl_cipher_suite_names_unittest.cc revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright (c) 2011 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 "net/ssl/ssl_cipher_suite_names.h"
6
7#include "base/basictypes.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace net {
11
12namespace {
13
14TEST(CipherSuiteNamesTest, Basic) {
15  const char *key_exchange, *cipher, *mac;
16  SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, 0xc001);
17  EXPECT_STREQ("ECDH_ECDSA", key_exchange);
18  EXPECT_STREQ("NULL", cipher);
19  EXPECT_STREQ("SHA1", mac);
20
21  SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, 0x009f);
22  EXPECT_STREQ("DHE_RSA", key_exchange);
23  EXPECT_STREQ("AES_256_CTR", cipher);
24  EXPECT_STREQ("GHASH_128", mac);
25
26  SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, 0xff31);
27  EXPECT_STREQ("???", key_exchange);
28  EXPECT_STREQ("???", cipher);
29  EXPECT_STREQ("???", mac);
30}
31
32TEST(CipherSuiteNamesTest, ParseSSLCipherString) {
33  uint16 cipher_suite = 0;
34  EXPECT_TRUE(ParseSSLCipherString("0x0004", &cipher_suite));
35  EXPECT_EQ(0x00004u, cipher_suite);
36
37  EXPECT_TRUE(ParseSSLCipherString("0xBEEF", &cipher_suite));
38  EXPECT_EQ(0xBEEFu, cipher_suite);
39}
40
41TEST(CipherSuiteNamesTest, ParseSSLCipherStringFails) {
42  const char* const cipher_strings[] = {
43    "0004",
44    "0x004",
45    "0xBEEFY",
46  };
47
48  for (size_t i = 0; i < arraysize(cipher_strings); ++i) {
49    uint16 cipher_suite = 0;
50    EXPECT_FALSE(ParseSSLCipherString(cipher_strings[i], &cipher_suite));
51  }
52}
53
54}  // anonymous namespace
55
56}  // namespace net
57