blob: d5bafb5fcf8ec6e2ab038596c9cd82f217d959f4 [file]
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "crypto/default/trust_store.h"
#include <string>
#include "absl/status/status.h"
#include "absl/status/status_matchers.h"
#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "testing/test_file_utils.h"
namespace credentio {
namespace {
using ::absl_testing::IsOk;
using ::absl_testing::StatusIs;
using ::testing::HasSubstr;
constexpr absl::string_view kTrustAnchors =
"c2pa/testing/testdata/keys/trust_anchors.pem";
TEST(LoadTrustStore, Success) {
auto pem = credentio_testing::GetContents(kTrustAnchors);
ASSERT_TRUE(pem.ok());
EXPECT_THAT(credentio::LoadTrustStore(*pem), IsOk());
}
TEST(LoadTrustStore, EmptyPem) {
EXPECT_THAT(credentio::LoadTrustStore(""),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("No certificates found")));
}
TEST(LoadTrustStore, MalformedPem) {
EXPECT_THAT(credentio::LoadTrustStore(R"(
-----BEGIN CERTIFICATE-----
blah blah
-----END CERTIFICATE-----
)"),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("No certificates found")));
}
} // namespace
} // namespace credentio