Kelvin Zhang | 33c62fc | 2021-05-14 17:15:50 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include "install/spl_check.h" |
| 20 | #include "ota_metadata.pb.h" |
| 21 | |
| 22 | using build::tools::releasetools::OtaMetadata; |
| 23 | class SplCheckUnittest : public ::testing::Test { |
| 24 | public: |
| 25 | OtaMetadata metadata; |
| 26 | }; |
| 27 | |
| 28 | TEST_F(SplCheckUnittest, OlderSPL) { |
| 29 | metadata.set_spl_downgrade(false); |
| 30 | metadata.mutable_postcondition()->set_security_patch_level("2021-04-25"); |
| 31 | ASSERT_TRUE(ViolatesSPLDowngrade(metadata, "2021-05-01")); |
| 32 | } |
| 33 | |
| 34 | TEST_F(SplCheckUnittest, NewerSPL) { |
| 35 | metadata.set_spl_downgrade(false); |
| 36 | metadata.mutable_postcondition()->set_security_patch_level("2021-06-01"); |
| 37 | ASSERT_FALSE(ViolatesSPLDowngrade(metadata, "2021-05-05")); |
| 38 | } |
| 39 | |
| 40 | TEST_F(SplCheckUnittest, OlderSPLPermit) { |
| 41 | // If spl_downgrade is set to true, OTA should be permitted |
| 42 | metadata.set_spl_downgrade(true); |
| 43 | metadata.mutable_postcondition()->set_security_patch_level("2021-04-11"); |
| 44 | ASSERT_FALSE(ViolatesSPLDowngrade(metadata, "2021-05-11")); |
| 45 | } |