Commit f0fd1a60 authored by Tony Mak's avatar Tony Mak
Browse files

CTS test for new behaviour of setDelegatedCertInstaller

1. Added CtsDeviceAndProfileOwnerApp23 to verify behavior of API targeting
   23.

2. Fixed an issue that MoreAsserts is not found after the cts_v2 CL by
   including "<uses-library android:name="android.test.runner" />".

Bug: 27285599
Bug: 27493070

Change-Id: Id78f512818c7fef963c8d93f597a413611cf302b
parent ed619f39
......@@ -91,6 +91,7 @@ cts_support_packages := \
CtsCppToolsApp \
CtsDeviceAdminApp23 \
CtsDeviceAdminApp24 \
CtsDeviceAndProfileOwnerApp23 \
CtsDeviceAndProfileOwnerApp \
CtsDeviceInfo \
CtsDeviceOsTestApp \
......
# Copyright (C) 2015 The Android Open Source Project
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -12,23 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
LOCAL_PATH:= $(call my-dir)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := CtsDeviceAndProfileOwnerApp
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner ub-uiautomator
LOCAL_SDK_VERSION := current
# tag this module as a cts test artifact
LOCAL_COMPATIBILITY_SUITE := cts
include $(BUILD_CTS_PACKAGE)
# Build the test APKs using their own makefiles
include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
# Copyright (C) 2016 The Android Open Source Project
#
# 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.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := CtsDeviceAndProfileOwnerApp23
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner ub-uiautomator
LOCAL_SDK_VERSION := current
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/../res
# tag this module as a cts test artifact
LOCAL_COMPATIBILITY_SUITE := cts
include $(BUILD_CTS_PACKAGE)
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.cts.deviceandprofileowner">
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<application>
<uses-library android:name="android.test.runner" />
<receiver
android:name="com.android.cts.deviceandprofileowner.BaseDeviceAdminTest$BasicAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
<instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.cts.deviceandprofileowner"
android:label="Profile and Device Owner CTS Tests API 23"/>
</manifest>
# Copyright (C) 2016 The Android Open Source Project
#
# 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.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := CtsDeviceAndProfileOwnerApp
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner ub-uiautomator
LOCAL_SDK_VERSION := current
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/../res
# tag this module as a cts test artifact
LOCAL_COMPATIBILITY_SUITE := cts
include $(BUILD_CTS_PACKAGE)
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
<!-- Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<application>
<uses-library android:name="android.test.runner" />
<receiver
android:name="com.android.cts.deviceandprofileowner.BaseDeviceAdminTest$BasicAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
......
......@@ -19,6 +19,8 @@ import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.UserManager;
import android.test.InstrumentationTestCase;
......@@ -57,4 +59,10 @@ public class BaseDeviceAdminTest extends InstrumentationTestCase {
mDevicePolicyManager.isProfileOwnerApp(PACKAGE_NAME) ||
mDevicePolicyManager.isDeviceOwnerApp(PACKAGE_NAME));
}
protected int getTargetApiLevel() throws Exception {
final PackageManager pm = mContext.getPackageManager();
final PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), /* flags =*/ 0);
return pi.applicationInfo.targetSdkVersion;
}
}
......@@ -22,21 +22,10 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.security.KeyChain;
import android.os.Build;
import android.security.KeyChainException;
import android.test.AndroidTestCase;
import android.util.Base64;
import android.util.Base64InputStream;
import java.io.ByteArrayInputStream;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import android.test.MoreAsserts;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
......@@ -48,6 +37,8 @@ import java.util.concurrent.TimeUnit;
public class DelegatedCertInstallerTest extends BaseDeviceAdminTest {
private static final String CERT_INSTALLER_PACKAGE = "com.android.cts.certinstaller";
private static final String NOT_EXIST_CERT_INSTALLER_PACKAGE
= "com.android.cts.certinstaller.not_exist";
private static final String ACTION_INSTALL_CERT = "com.android.cts.certinstaller.install_cert";
private static final String ACTION_REMOVE_CERT = "com.android.cts.certinstaller.remove_cert";
......@@ -226,6 +217,27 @@ public class DelegatedCertInstallerTest extends BaseDeviceAdminTest {
assertResult("installKeyPair", true);
}
/**
* If DPC is targeting N+, @{link IllegalArgumentException } should be thrown if the package
* is missing.
*/
public void testSetNotExistCertInstallerPackage() throws Exception {
boolean shouldThrowException = getTargetApiLevel() >= Build.VERSION_CODES.N;
try {
mDpm.setCertInstallerPackage(
ADMIN_RECEIVER_COMPONENT, NOT_EXIST_CERT_INSTALLER_PACKAGE);
if (shouldThrowException) {
fail("Did not throw IllegalArgumentException");
}
} catch (IllegalArgumentException ex) {
if (!shouldThrowException) {
fail("Should not throw exception");
}
MoreAsserts.assertContainsRegex("is not installed on the current user",
ex.getMessage());
}
}
/**
* installKeyPair() requires the system to have a lockscreen password, which should have been
* set by the host side test.
......
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
package com.android.cts.devicepolicy;
/**
* To verify PO APIs targeting API level 23.
*/
public class ProfileOwnerTestApi23 extends BaseDevicePolicyTest {
protected static final String DEVICE_ADMIN_PKG = "com.android.cts.deviceandprofileowner";
protected static final String DEVICE_ADMIN_APK = "CtsDeviceAndProfileOwnerApp23.apk";
protected static final String ADMIN_RECEIVER_TEST_CLASS
= ".BaseDeviceAdminTest$BasicAdminReceiver";
protected static final String CLEAR_PROFILE_OWNER_TEST_CLASS =
DEVICE_ADMIN_PKG + ".ClearProfileOwnerTest";
private int mUserId;
@Override
protected void setUp() throws Exception {
super.setUp();
if (mHasFeature) {
mUserId = USER_OWNER;
installAppAsUser(DEVICE_ADMIN_APK, mUserId);
setProfileOwnerOrFail(DEVICE_ADMIN_PKG + "/" + ADMIN_RECEIVER_TEST_CLASS, mUserId);
}
}
@Override
protected void tearDown() throws Exception {
if (mHasFeature) {
assertTrue("Failed to remove profile owner.",
runDeviceTestsAsUser(DEVICE_ADMIN_PKG, CLEAR_PROFILE_OWNER_TEST_CLASS,
mUserId));
}
super.tearDown();
}
public void testDelegatedCertInstaller() throws Exception {
assertTrue("DelegatedCertInstaller failed", runDeviceTestsAsUser(DEVICE_ADMIN_PKG,
".DelegatedCertInstallerTest", "testSetNotExistCertInstallerPackage", mUserId));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment