/*
* Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nuxeo - initial API and implementation
*/
package org.eclipse.ecr.runtime;
import java.io.File;
import junit.framework.TestCase;
import org.eclipse.ecr.runtime.api.Framework;
import org.eclipse.ecr.runtime.api.login.SystemLoginRestrictionManager;
import org.eclipse.ecr.runtime.util.SimpleRuntime;
import org.nuxeo.common.Environment;
public class TestSystemLoginRestriction extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
System.setProperty("org.nuxeo.runtime.testing", "true");
Environment env = new Environment(new File(System.getProperty("java.io.tmpdir")));
Environment.setDefault(env);
Framework.initialize(new SimpleRuntime());
}
public void testRestrictions() {
SystemLoginRestrictionManager srm = new SystemLoginRestrictionManager();
assertTrue(srm.isRemoteSystemLoginRestricted());
srm = new SystemLoginRestrictionManager();
Framework.getProperties().put(SystemLoginRestrictionManager.RESTRICT_REMOTE_SYSTEM_LOGIN_PROP, "false");
assertFalse(srm.isRemoteSystemLoginRestricted());
srm = new SystemLoginRestrictionManager();
Framework.getProperties().put(SystemLoginRestrictionManager.RESTRICT_REMOTE_SYSTEM_LOGIN_PROP, "true");
assertTrue(srm.isRemoteSystemLoginRestricted());
srm = new SystemLoginRestrictionManager();
assertFalse(srm.isRemoveSystemLoginAllowedForInstance("RemoteHost"));
srm = new SystemLoginRestrictionManager();
Framework.getProperties().put(SystemLoginRestrictionManager.REMOTE_SYSTEM_LOGIN_TRUSTED_INSTANCES_PROP, "RemoteHost");
assertTrue(srm.isRemoveSystemLoginAllowedForInstance("RemoteHost"));
srm = new SystemLoginRestrictionManager();
Framework.getProperties().put(SystemLoginRestrictionManager.REMOTE_SYSTEM_LOGIN_TRUSTED_INSTANCES_PROP, "RemoteHost,RemoteHost2");
assertTrue(srm.isRemoveSystemLoginAllowedForInstance("RemoteHost"));
assertTrue(srm.isRemoveSystemLoginAllowedForInstance("RemoteHost2"));
assertFalse(srm.isRemoveSystemLoginAllowedForInstance(""));
srm = new SystemLoginRestrictionManager();
Framework.getProperties().put(SystemLoginRestrictionManager.REMOTE_SYSTEM_LOGIN_TRUSTED_INSTANCES_PROP, "RemoteHost,RemoteHost2,");
assertTrue(srm.isRemoveSystemLoginAllowedForInstance("RemoteHost"));
assertTrue(srm.isRemoveSystemLoginAllowedForInstance("RemoteHost2"));
assertFalse(srm.isRemoveSystemLoginAllowedForInstance(""));
}
}