1 /*
2 * Copyright 2023 Google LLC.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18
19 #include <filesystem>
20 #include <memory>
21 #include <string>
22 #include <vector>
23
24 #include "act/act.h"
25 #include "act/act.pb.h"
26 #include "act/act_v0/act_v0.h"
27 #include "act/act_v0/testing/transcript.pb.h"
28 #include "private_join_and_compute/util/proto_util.h"
29 #include "private_join_and_compute/util/status_testing.inc"
30
31 namespace private_join_and_compute {
32 namespace anonymous_counting_tokens {
33 namespace {
34
35 const char kTranscriptPathBase[] = "act/act_v0/testing/transcripts/";
36
TEST(GoldenTranscriptTest,TranscriptPassesValidityTests)37 TEST(GoldenTranscriptTest, TranscriptPassesValidityTests) {
38 auto act = AnonymousCountingTokensV0::Create();
39
40 std::vector<std::string> transcript_paths;
41
42 for (const auto& entry :
43 std::filesystem::directory_iterator(kTranscriptPathBase)) {
44 transcript_paths.push_back(std::string(entry.path()));
45 }
46
47 for (const auto& transcript_path : transcript_paths) {
48 ASSERT_OK_AND_ASSIGN(
49 Transcript transcript,
50 ProtoUtils::ReadProtoFromFile<Transcript>(transcript_path));
51
52 EXPECT_OK(act->CheckClientParameters(
53 transcript.scheme_parameters(),
54 transcript.client_parameters().public_parameters(),
55 transcript.server_parameters().public_parameters(),
56 transcript.server_parameters().private_parameters()));
57
58 std::vector<std::string> client_fingerprints(
59 transcript.fingerprints().begin(), transcript.fingerprints().end());
60 EXPECT_OK(act->CheckTokensRequest(
61 client_fingerprints, transcript.tokens_request(),
62 transcript.scheme_parameters(),
63 transcript.client_parameters().public_parameters(),
64 transcript.server_parameters().public_parameters(),
65 transcript.server_parameters().private_parameters()));
66
67 std::vector<std::string> messages(transcript.messages().begin(),
68 transcript.messages().end());
69 EXPECT_OK(act->VerifyTokensResponse(
70 messages, transcript.tokens_request(),
71 transcript.tokens_request_private_state(), transcript.tokens_response(),
72 transcript.scheme_parameters(),
73 transcript.client_parameters().public_parameters(),
74 transcript.client_parameters().private_parameters(),
75 transcript.server_parameters().public_parameters()));
76 }
77 }
78
79 } // namespace
80 } // namespace anonymous_counting_tokens
81 } // namespace private_join_and_compute
82