#
# Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics
# Laboratory LLC.
#
# This file is part of the Bundle Protocol Security Library (BSL).
#
# 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
#     http://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.
#
# This work was performed for the Jet Propulsion Laboratory, California
# Institute of Technology, sponsored by the United States Government under
# the prime contract 80NM0018D0004 between the Caltech and NASA under
# subcontract 1700763.
#
from _test_util import _TestCase, DataFormat, BundleDestLoc
from test_bpa import TestAgent

# Test Cases utilizing JSON policy definitions


class Test_ION_JSON_Policy(TestAgent):

    def test_json_source_bib_bcb(self):
        self._single_test(_TestCase(
            # A bundle with just the **payload** block
            input_data=[
                [7, 0, 0, [2, [1, 2]], [2, [2, 1]], [2, [2, 1]], [0, 40], 1000000],
                [1, 1, 0, 0, bytes.fromhex(
                    '526561647920746F2067656E657261746520612033322D62797465207061796C6F6164')]
            ],
            # Bundle with BIB and BCB
            expected_output=[
                [7, 0, 0, [2, [1, 2]], [2, [2, 1]], [2, [2, 1]], [0, 40], 1000000],
                [12, 3, 1, 0, bytes.fromhex(
                    '8101020182028202018482014c5477656c76653132313231328202018203581869c411276fecddc4780df42c8a2af89296fabf34d7fae7008204008181820150efa4b5ac0108e3816c5606479801bc04')],
                [11, 2, 0, 0, bytes.fromhex(
                    '810101018202820201828201078203008181820158403bdc69b3a34a2b5d3a8554368bd1e808f606219d2a10a846eae3886ae4ecc83c4ee550fdfb1cc636b904e2f1a73e303dcd4b6ccece003e95e8164dcc89a156e1')],
                [1, 1, 0, 0, bytes.fromhex(
                    '3a09c1e63fe23a7f66a59c7303837241e070b02619fc59c5214a22f08cd70795e73e9a')]
            ],
            policy_config='mock-bpa-test/policy_provider_test.json',
            bundle_dest_loc=BundleDestLoc.APPIN,
            key_set="mock-bpa-test/key_set_1.json",
            is_working=True,
            input_data_format=DataFormat.BUNDLEARRAY,
            expected_output_format=DataFormat.BUNDLEARRAY,
            use_bcb_rng=True
        ))
