blob: 2ae0b1c4edbcb8ea8822e16f76161f0c08cbb06f [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 "testing/fake_assertion_validator.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "constants/status_codes.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "jumbf/box.h"
#include "jumbf/uri.h"
#include "proto/assertion.pb.h"
#include "proto/ingredient_assertion.pb.h"
#include "proto/manifest.pb.h"
#include "testing/proto_test_utils.h"
#include "testing/test_validation_tracker.h"
namespace credentio {
namespace {
using ::credentio_testing::EqualsProto;
using ::testing::ElementsAre;
using ::testing::IsEmpty;
TEST(FakeAssertionValidatorTest, TrackerIsPopulated) {
FakeAssertionValidator assertion_validator(
/*failures=*/{FailureStatusCode::kAssertionCborInvalid},
/*successes=*/{SuccessStatusCode::kClaimSignatureValidated});
TestValidationTracker t;
jumbf::SuperBox root_box;
auto uri_resolver = jumbf::UriResolver::WithSingleRootChild(&root_box);
Manifest manifest;
assertion_validator.ValidateClaimAssertions(uri_resolver,
/*redacted_assertion_paths=*/{},
manifest, t.tracker());
EXPECT_THAT(t.GetFailures(),
ContainsFailure(FailureStatusCode::kAssertionCborInvalid));
EXPECT_THAT(t.GetSuccesses(),
ContainsSuccess(SuccessStatusCode::kClaimSignatureValidated));
}
TEST(FakeAssertionValidatorTest, AssertionsArePopulated) {
FakeAssertionValidator assertion_validator(/*failures=*/{}, /*successes=*/{});
absl::string_view manifest_label = "some_manifest_label";
TestValidationTracker t;
jumbf::SuperBox root_box;
auto uri_resolver = jumbf::UriResolver::WithSingleRootChild(&root_box);
Assertion assertion;
assertion.mutable_ingredient_v2()->set_description("some_description");
assertion_validator.SetOutputAssertions("/c2pa/some_manifest_label",
{assertion});
Manifest manifest;
manifest.set_label(manifest_label);
assertion_validator.ValidateClaimAssertions(
uri_resolver, /*redacted_assertion_paths=*/{}, manifest, t.tracker());
EXPECT_THAT(manifest.assertions(), ElementsAre(EqualsProto(assertion)));
EXPECT_THAT(t.GetFailures(), IsEmpty());
}
} // namespace
} // namespace credentio