blob: 719df74e5fada5d5b7d2cfda22dbe6e2a165c706 [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_claim_validator.h"
#include "absl/types/span.h"
#include "constants/status_codes.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "jumbf/box.h"
#include "proto/generator_info.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::Optional;
TEST(FakeClaimValidatorTest, TrackerIsPopulated) {
FakeClaimValidator claim_validator(
/*failures=*/{FailureStatusCode::kClaimCborInvalid},
/*informationals=*/
{InformationalStatusCode::kIngredientUnknownProvenance},
/*successes=*/{SuccessStatusCode::kClaimSignatureValidated});
TestValidationTracker t;
jumbf::SuperBox active_manifest;
claim_validator.Validate(active_manifest, t.tracker());
EXPECT_THAT(t.GetFailures(),
ContainsFailure(FailureStatusCode::kClaimCborInvalid));
EXPECT_THAT(t.GetInformationals(),
ContainsInformational(
InformationalStatusCode::kIngredientUnknownProvenance));
EXPECT_THAT(t.GetSuccesses(),
ContainsSuccess(SuccessStatusCode::kClaimSignatureValidated));
}
TEST(FakeClaimValidatorTest, ClaimIsPopulated) {
Claim claim;
claim.mutable_claim_generator_info()->set_name("some_name");
FakeClaimValidator claim_validator(/*failures=*/{}, /*informationals=*/{},
/*successes=*/{});
claim_validator.SetClaimResult("some_label", claim);
claim_validator.SetClaimFailures("some_label",
{FailureStatusCode::kClaimCborInvalid});
claim_validator.SetClaimInformationals(
"some_label", {InformationalStatusCode::kIngredientUnknownProvenance});
claim_validator.SetClaimSuccesses(
"some_label", {SuccessStatusCode::kClaimSignatureValidated});
TestValidationTracker t;
jumbf::SuperBox active_manifest;
active_manifest.description.label = "some_label";
EXPECT_THAT(claim_validator.Validate(active_manifest, t.tracker()),
Optional(EqualsProto(claim)));
EXPECT_THAT(t.GetFailures(),
ContainsFailure(FailureStatusCode::kClaimCborInvalid));
EXPECT_THAT(t.GetInformationals(),
ContainsInformational(
InformationalStatusCode::kIngredientUnknownProvenance));
EXPECT_THAT(t.GetSuccesses(),
ContainsSuccess(SuccessStatusCode::kClaimSignatureValidated));
}
} // namespace
} // namespace credentio