proxygen
TokenBindingClientExtensionTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
11 
13 
14 using namespace testing;
15 
16 namespace fizz {
17 namespace extensions {
18 namespace test {
19 
21  public:
22  void SetUp() override {
23  context_ = std::make_shared<TokenBindingContext>();
24  extensions_ = std::make_shared<TokenBindingClientExtension>(context_);
25  }
26 
29  TokenBindingKeyParameters keyParam) {
31  params.version = version;
32  params.key_parameters_list.push_back(keyParam);
33  serverExtensions_.push_back(encodeExtension(params));
34  }
35 
36  std::vector<Extension> serverExtensions_;
37  std::shared_ptr<TokenBindingClientExtension> extensions_;
38  std::shared_ptr<TokenBindingContext> context_;
39 };
40 
41 TEST_F(TokenBindingClientExtensionTest, TestValidCheckExtensions) {
42  setUpServerHelloExtensions(
43  TokenBindingProtocolVersion::token_binding_0_14,
44  TokenBindingKeyParameters::ecdsap256);
45  extensions_->onEncryptedExtensions(serverExtensions_);
46  EXPECT_TRUE(extensions_->getVersion().hasValue());
47  EXPECT_EQ(
48  extensions_->getVersion(),
49  TokenBindingProtocolVersion::token_binding_0_14);
50  EXPECT_TRUE(extensions_->getNegotiatedKeyParam().hasValue());
51  EXPECT_EQ(
52  extensions_->getNegotiatedKeyParam(),
53  TokenBindingKeyParameters::ecdsap256);
54 }
55 
57  extensions_->onEncryptedExtensions(serverExtensions_);
58  EXPECT_FALSE(extensions_->getVersion().hasValue());
59  EXPECT_FALSE(extensions_->getNegotiatedKeyParam().hasValue());
60 }
61 
62 TEST_F(TokenBindingClientExtensionTest, TestServerBadKeyParam) {
63  setUpServerHelloExtensions(
64  TokenBindingProtocolVersion::token_binding_0_14,
65  TokenBindingKeyParameters::rsa2048_pss);
66  context_->setSupportedVersions(std::vector<TokenBindingProtocolVersion>{
67  TokenBindingProtocolVersion::token_binding_0_12});
68  context_->setSupportedKeyParameters(std::vector<TokenBindingKeyParameters>{
69  TokenBindingKeyParameters::rsa2048_pkcs1_5});
70 
72  extensions_->onEncryptedExtensions(serverExtensions_), FizzException);
73  EXPECT_FALSE(extensions_->getVersion().hasValue());
74  EXPECT_FALSE(extensions_->getNegotiatedKeyParam().hasValue());
75 }
76 
77 TEST_F(TokenBindingClientExtensionTest, TestServerHigherVersion) {
78  setUpServerHelloExtensions(
79  TokenBindingProtocolVersion::token_binding_0_14,
80  TokenBindingKeyParameters::ecdsap256);
81  context_->setSupportedVersions(std::vector<TokenBindingProtocolVersion>{
82  TokenBindingProtocolVersion::token_binding_0_12});
83 
85  extensions_->onEncryptedExtensions(serverExtensions_), FizzException);
86  EXPECT_FALSE(extensions_->getVersion().hasValue());
87  EXPECT_FALSE(extensions_->getNegotiatedKeyParam().hasValue());
88 }
89 
90 TEST_F(TokenBindingClientExtensionTest, TestServerLowerVersion) {
91  setUpServerHelloExtensions(
92  TokenBindingProtocolVersion::token_binding_0_12,
93  TokenBindingKeyParameters::ecdsap256);
94  context_->setSupportedVersions(std::vector<TokenBindingProtocolVersion>{
95  TokenBindingProtocolVersion::token_binding_0_14});
96 
97  extensions_->onEncryptedExtensions(serverExtensions_);
98  EXPECT_FALSE(extensions_->getVersion().hasValue());
99  EXPECT_FALSE(extensions_->getNegotiatedKeyParam().hasValue());
100 }
101 } // namespace test
102 } // namespace extensions
103 } // namespace fizz
void setUpServerHelloExtensions(TokenBindingProtocolVersion version, TokenBindingKeyParameters keyParam)
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
TEST_F(TestInfoTest, Names)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TokenBindingKeyParameters
Definition: Types.h:33
ProtocolVersion version
TokenBindingProtocolVersion version
Definition: Types.h:42
constexpr Params params[]
Definition: Actions.h:16
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::vector< TokenBindingKeyParameters > key_parameters_list
Definition: Types.h:43
TokenBindingProtocolVersion
Definition: Types.h:22
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113