MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / TEST_P

Function TEST_P

tests/unit/test_http_pairing.cpp:81–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79struct PairingTest: testing::TestWithParam<std::tuple<pairing_input, pairing_output>> {};
80
81TEST_P(PairingTest, Run) {
82 auto [input, expected] = GetParam();
83
84 boost::property_tree::ptree tree;
85
86 setup(PRIVATE_KEY, PUBLIC_CERT);
87
88 // phase 1
89 getservercert(*input.session, tree, input.pin);
90 ASSERT_EQ(tree.get<int>("root.paired") == 1, expected.phase_1_success);
91 if (!expected.phase_1_success) {
92 return;
93 }
94
95 // phase 2
96 clientchallenge(*input.session, tree, input.client_challenge);
97 ASSERT_EQ(tree.get<int>("root.paired") == 1, expected.phase_2_success);
98 if (!expected.phase_2_success) {
99 return;
100 }
101
102 // phase 3
103 serverchallengeresp(*input.session, tree, input.server_challenge_resp);
104 ASSERT_EQ(tree.get<int>("root.paired") == 1, expected.phase_3_success);
105 if (!expected.phase_3_success) {
106 return;
107 }
108 input.session->serverchallenge = input.override_server_challenge;
109
110 // phase 4
111 auto input_client_cert = input.session->client.cert; // Will be moved
112 auto add_cert = std::make_shared<safe::queue_t<crypto::x509_t>>(30);
113 clientpairingsecret(*input.session, add_cert, tree, input.client_pairing_secret);
114 ASSERT_EQ(tree.get<int>("root.paired") == 1, expected.phase_4_success);
115
116 // Check that we actually added the input client certificate to `add_cert`
117 if (expected.phase_4_success) {
118 ASSERT_EQ(add_cert->peek(), true);
119 auto cert = add_cert->pop();
120 char added_subject_name[256];
121 X509_NAME_oneline(X509_get_subject_name(cert.get()), added_subject_name, sizeof(added_subject_name));
122
123 auto input_cert = crypto::x509(input_client_cert);
124 char original_suject_name[256];
125 X509_NAME_oneline(X509_get_subject_name(input_cert.get()), original_suject_name, sizeof(original_suject_name));
126
127 ASSERT_EQ(std::string(added_subject_name), std::string(original_suject_name));
128 }
129}
130
131INSTANTIATE_TEST_SUITE_P(
132 TestWorkingPairing,

Callers

nothing calls this directly

Calls 10

setupFunction · 0.85
getservercertFunction · 0.85
clientchallengeFunction · 0.85
serverchallengerespFunction · 0.85
clientpairingsecretFunction · 0.85
x509Function · 0.85
stringFunction · 0.85
peekMethod · 0.45
popMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected