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