blob: 709b69c9f65afd3ac14014cf58be61862a81537f [file] [log] [blame]
Kelvin Zhange6312252021-05-14 17:15:50 -04001/*
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
22using build::tools::releasetools::OtaMetadata;
23class SplCheckUnittest : public ::testing::Test {
24 public:
25 OtaMetadata metadata;
26};
27
28TEST_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
34TEST_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
40TEST_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}