1 /* 2 * Copyright (C) 2010 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 package com.android.exchange.adapter; 18 19 import com.android.emailcommon.provider.Policy; 20 import com.android.exchange.adapter.ProvisionParser; 21 22 import android.content.Context; 23 import android.test.suitebuilder.annotation.SmallTest; 24 25 import java.io.ByteArrayInputStream; 26 import java.io.IOException; 27 28 /** 29 * You can run this entire test case with: 30 * runtest -c com.android.exchange.adapter.ProvisionParserTests exchange 31 */ 32 @SmallTest 33 public class ProvisionParserTests extends SyncAdapterTestCase { 34 private final ByteArrayInputStream mTestInputStream = 35 new ByteArrayInputStream("ABCDEFG".getBytes()); 36 37 // A good sample of an Exchange 2003 (WAP) provisioning document for end-to-end testing 38 private String mWapProvisioningDoc1 = 39 "<wap-provisioningdoc>" + 40 "<characteristic type=\"SecurityPolicy\"><parm name=\"4131\" value=\"0\"/>" + 41 "</characteristic>" + 42 "<characteristic type=\"Registry\">" + 43 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\AE\\" + 44 "{50C13377-C66D-400C-889E-C316FC4AB374}\">" + 45 "<parm name=\"AEFrequencyType\" value=\"1\"/>" + 46 "<parm name=\"AEFrequencyValue\" value=\"5\"/>" + 47 "</characteristic>" + 48 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\">" + 49 "<parm name=\"DeviceWipeThreshold\" value=\"20\"/>" + 50 "</characteristic>" + 51 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\">" + 52 "<parm name=\"CodewordFrequency\" value=\"5\"/>" + 53 "</characteristic>" + 54 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\LAP\\lap_pw\">" + 55 "<parm name=\"MinimumPasswordLength\" value=\"8\"/>" + 56 "</characteristic>" + 57 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\LAP\\lap_pw\">" + 58 "<parm name=\"PasswordComplexity\" value=\"0\"/>" + 59 "</characteristic>" + 60 "</characteristic>" + 61 "</wap-provisioningdoc>"; 62 63 // Provisioning document with passwords turned off 64 private String mWapProvisioningDoc2 = 65 "<wap-provisioningdoc>" + 66 "<characteristic type=\"SecurityPolicy\"><parm name=\"4131\" value=\"1\"/>" + 67 "</characteristic>" + 68 "<characteristic type=\"Registry\">" + 69 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\AE\\" + 70 "{50C13377-C66D-400C-889E-C316FC4AB374}\">" + 71 "<parm name=\"AEFrequencyType\" value=\"0\"/>" + 72 "<parm name=\"AEFrequencyValue\" value=\"5\"/>" + 73 "</characteristic>" + 74 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\">" + 75 "<parm name=\"DeviceWipeThreshold\" value=\"20\"/>" + 76 "</characteristic>" + 77 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\">" + 78 "<parm name=\"CodewordFrequency\" value=\"5\"/>" + 79 "</characteristic>" + 80 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\LAP\\lap_pw\">" + 81 "<parm name=\"MinimumPasswordLength\" value=\"8\"/>" + 82 "</characteristic>" + 83 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\LAP\\lap_pw\">" + 84 "<parm name=\"PasswordComplexity\" value=\"0\"/>" + 85 "</characteristic>" + 86 "</characteristic>" + 87 "</wap-provisioningdoc>"; 88 89 // Provisioning document with simple password, 4 chars, 5 failures 90 private String mWapProvisioningDoc3 = 91 "<wap-provisioningdoc>" + 92 "<characteristic type=\"SecurityPolicy\"><parm name=\"4131\" value=\"0\"/>" + 93 "</characteristic>" + 94 "<characteristic type=\"Registry\">" + 95 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\AE\\" + 96 "{50C13377-C66D-400C-889E-C316FC4AB374}\">" + 97 "<parm name=\"AEFrequencyType\" value=\"1\"/>" + 98 "<parm name=\"AEFrequencyValue\" value=\"2\"/>" + 99 "</characteristic>" + 100 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\">" + 101 "<parm name=\"DeviceWipeThreshold\" value=\"5\"/>" + 102 "</characteristic>" + 103 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\">" + 104 "<parm name=\"CodewordFrequency\" value=\"5\"/>" + 105 "</characteristic>" + 106 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\LAP\\lap_pw\">" + 107 "<parm name=\"MinimumPasswordLength\" value=\"4\"/>" + 108 "</characteristic>" + 109 "<characteristic type=\"HKLM\\Comm\\Security\\Policy\\LASSD\\LAP\\lap_pw\">" + 110 "<parm name=\"PasswordComplexity\" value=\"1\"/>" + 111 "</characteristic>" + 112 "</characteristic>" + 113 "</wap-provisioningdoc>"; 114 115 public void testWapProvisionParser1() throws IOException { 116 ProvisionParser parser = new ProvisionParser(getContext(), mTestInputStream); 117 parser.parseProvisionDocXml(mWapProvisioningDoc1); 118 Policy policy = parser.getPolicy(); 119 assertNotNull(policy); 120 // Check the settings to make sure they were parsed correctly 121 assertEquals(5*60, policy.mMaxScreenLockTime); // Screen lock time is in seconds 122 assertEquals(8, policy.mPasswordMinLength); 123 assertEquals(Policy.PASSWORD_MODE_STRONG, policy.mPasswordMode); 124 assertEquals(20, policy.mPasswordMaxFails); 125 assertTrue(policy.mRequireRemoteWipe); 126 } 127 128 public void testWapProvisionParser2() throws IOException { 129 ProvisionParser parser = new ProvisionParser(getContext(), mTestInputStream); 130 parser.parseProvisionDocXml(mWapProvisioningDoc2); 131 Policy policy = parser.getPolicy(); 132 assertNotNull(policy); 133 // Password should be set to none; others are ignored in this case. 134 assertEquals(Policy.PASSWORD_MODE_NONE, policy.mPasswordMode); 135 } 136 137 public void testWapProvisionParser3() throws IOException { 138 ProvisionParser parser = new ProvisionParser(getContext(), mTestInputStream); 139 parser.parseProvisionDocXml(mWapProvisioningDoc3); 140 Policy policy = parser.getPolicy(); 141 assertNotNull(policy); 142 // Password should be set to simple 143 assertEquals(2*60, policy.mMaxScreenLockTime); // Screen lock time is in seconds 144 assertEquals(4, policy.mPasswordMinLength); 145 assertEquals(Policy.PASSWORD_MODE_SIMPLE, policy.mPasswordMode); 146 assertEquals(5, policy.mPasswordMaxFails); 147 assertTrue(policy.mRequireRemoteWipe); 148 } 149 } 150