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