Commit f972e769 authored by lichenchong's avatar lichenchong
Browse files

Test case:

modify admin client test cases under directory of "simulator" work with
protocol 3.0.0.
parent b89045f3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -174,6 +174,17 @@ public class IntegrationTestCase {
        return adminClientConfiguration;
    }
    
    /**
     * Get a Kinetic admin client configuration with setting userId and key flexible.
     * <p>
     */
    protected AdminClientConfiguration getAdminClientConfig(int userId, String key) {
        AdminClientConfiguration adminClientConfiguration = getAdminClientConfig();
        adminClientConfiguration.setUserId(userId);
        adminClientConfiguration.setKey(key);
        return adminClientConfiguration;
    }

    /**
     * Restart the server and the Kinetic client.
     * <p>
+65 −65
Original line number Diff line number Diff line
@@ -19,11 +19,15 @@
 */
package com.seagate.kinetic.simulator.client.admin;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import kinetic.admin.ACL;
import kinetic.admin.Domain;
import kinetic.admin.Role;
import kinetic.client.KineticClient;
import kinetic.client.KineticClientFactory;
import kinetic.client.KineticException;
@@ -36,13 +40,6 @@ import com.google.protobuf.ByteString;
import com.seagate.kinetic.IntegrationTestCase;
import com.seagate.kinetic.admin.impl.DefaultAdminClient;
import com.seagate.kinetic.client.internal.ClientProxy.LCException;
import com.seagate.kinetic.proto.Kinetic.Message;
import com.seagate.kinetic.proto.Kinetic.Command.Security;
import com.seagate.kinetic.proto.Kinetic.Command.Security.ACL;
import com.seagate.kinetic.proto.Kinetic.Command.Security.ACL.HMACAlgorithm;
import com.seagate.kinetic.proto.Kinetic.Command.Security.ACL.Permission;
import com.seagate.kinetic.proto.Kinetic.Command.Security.ACL.Scope;
import com.seagate.kinetic.proto.Kinetic.Command.Status;

public class SecurityOperationTest extends IntegrationTestCase {

@@ -62,61 +59,63 @@ public class SecurityOperationTest extends IntegrationTestCase {

    @Test
    public void addAclTest() throws LCException, KineticException {
//        Message.Builder request = Message.newBuilder();
//
//        Security.Builder sb = request.getCommandBuilder().getBodyBuilder()
//                .getSecurityBuilder();
//
//        ACL.Builder acl = ACL.newBuilder();
//        acl.setIdentity(1);
//        acl.setKey(ByteString.copyFromUtf8("asdfasdf"));
//        acl.setHmacAlgorithm(HMACAlgorithm.HmacSHA1);
//
//        Scope.Builder domain = Scope.newBuilder();
//
//        for (Permission role : Permission.values()) {
//            if (!role.equals(Permission.INVALID_PERMISSION)) {
//                domain.addPermission(role);
//            }
//        }
//
//        acl.addScope(domain);
//
//        sb.addAcl(acl.build());
//
//        Message respond = this.kineticClient.configureSecurityPolicy(request);
//
//        assertTrue(respond.getCommand().getStatus().getCode()
//                .equals(Status.StatusCode.SUCCESS));
//        this.kineticClient.close();
//
//        // right user, wrong key
//        KineticClient kineticClient2 = KineticClientFactory
//                .createInstance(getClientConfig(1, "asdfasdf2"));
//        try {
//
//            kineticClient2.get(ByteString.copyFromUtf8("1234").toByteArray());
//            fail("no exception was thrown");
//        } catch (Exception e) {
//            logger.info("caught expected exception");
//        }
//
//        kineticClient2.close();
//
//        // right user/key
//        KineticClient kineticClient3 = KineticClientFactory
//                .createInstance(getClientConfig(1, "asdfasdf"));
//        try {
//
//            kineticClient3.get(ByteString.copyFromUtf8("1234").toByteArray());
//
//        } catch (Exception e) {
//            logger.info("caught unexpected exception");
//            fail("caught unexpected exception");
//        }
//
//        kineticClient3.close();
//
        List<Role> roles1 = new ArrayList<Role>();
        roles1.add(Role.DELETE);
        roles1.add(Role.GETLOG);
        roles1.add(Role.READ);
        roles1.add(Role.RANGE);
        roles1.add(Role.SECURITY);
        roles1.add(Role.SETUP);
        roles1.add(Role.WRITE);
        roles1.add(Role.P2POP);

        Domain domain1 = new Domain();
        domain1.setRoles(roles1);

        List<Domain> domains1 = new ArrayList<Domain>();
        domains1.add(domain1);

        List<ACL> acls = new ArrayList<ACL>();
        ACL acl1 = new ACL();
        acl1.setDomains(domains1);
        acl1.setUserId(1);
        acl1.setKey("asdfasdf");

        acls.add(acl1);

        try {
            getAdminClient().setSecurity(acls, null, null, null, null);
        } catch (KineticException e1) {
            fail("set security throw exception: " + e1.getMessage());
        }

        // right user, wrong key
        KineticClient kineticClient2 = KineticClientFactory
                .createInstance(getClientConfig(1, "asdfasdf2"));
        try {

            kineticClient2.get(ByteString.copyFromUtf8("1234").toByteArray());
            fail("no exception was thrown");
        } catch (Exception e) {
            logger.info("caught expected exception");
        }

        kineticClient2.close();

        // right user/key
        KineticClient kineticClient3 = KineticClientFactory
                .createInstance(getClientConfig(1, "asdfasdf"));
        try {

            kineticClient3.get(ByteString.copyFromUtf8("1234").toByteArray());

        } catch (Exception e) {
            logger.info("caught unexpected exception");
            fail("caught unexpected exception");
        }

        kineticClient3.close();

//        // wrong user, right key
//        KineticClient kineticClient4 = KineticClientFactory
//                .createInstance(getClientConfig(2, "asdfasdf"));
@@ -126,8 +125,9 @@ public class SecurityOperationTest extends IntegrationTestCase {
//            fail("no exception was thrown");
//        } catch (Exception e) {
//            logger.info("caught expected exception");
//        }
//
//        } finally {
//            kineticClient4.close();
//        }

    }
}
+199 −440

File changed.

Preview size limit exceeded, changes collapsed.

+41 −20
Original line number Diff line number Diff line
@@ -19,8 +19,14 @@
 */
package com.seagate.kinetic.simulator.client.admin.impl;

import static org.junit.Assert.assertTrue;
import static com.seagate.kinetic.KineticTestHelpers.setDefaultAcls;
import static com.seagate.kinetic.KineticTestHelpers.toByteArray;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.List;

import kinetic.admin.ACL;
import kinetic.client.KineticException;

import org.junit.Test;
@@ -44,12 +50,14 @@ public class FirmwareDownloadTest extends IntegrationTestCase {
    @SimulatorOnly
    public void testFirmwareDownload_WithCorrectPin() {
        byte[] firmwareInfo = "firmware download info after pin set".getBytes();
        byte[] newPin = "123".getBytes();
        byte[] newErasePin = toByteArray("123");

        List<ACL> acls = new ArrayList<ACL>();
        acls = setDefaultAcls();
        try {
            getAdminClient().setup(null, newPin, 0, false);
            getAdminClient().firmwareDownload(newPin, firmwareInfo);
            getAdminClient().setup(newPin, null, 0, false);
            getAdminClient().setSecurity(acls, null, null, null, newErasePin);
            getAdminClient().firmwareDownload(newErasePin, firmwareInfo);
            getAdminClient().setSecurity(acls, null, null, newErasePin, null);
        } catch (KineticException e) {
            fail("firmware download failed");
        }
@@ -57,20 +65,33 @@ public class FirmwareDownloadTest extends IntegrationTestCase {

    @Test
    @SimulatorOnly
    public void testFirmwareDownload_WithIncorrectPin() throws KineticException {
//        byte[] firmwareInfo = "firmware download info after pin set".getBytes();
//        byte[] newPin = "123".getBytes();
//
//        getAdminClient().setup(null, newPin, 0, false);
//
//        byte[] incorrectPin = "456".getBytes();
//
//        try {
//            getAdminClient().firmwareDownload(incorrectPin, firmwareInfo);
//            fail("firmware download failed");
//        } catch (KineticException e) {
//            assertTrue(e.getMessage().contains("Pin not match"));
//            getAdminClient().setup(newPin, null, 0, false);
//        }
    public void testFirmwareDownload_WithIncorrectPin() {
        byte[] firmwareInfo = "firmware download info after pin set".getBytes();
        byte[] newErasePin = toByteArray("123");

        List<ACL> acls = new ArrayList<ACL>();
        acls = setDefaultAcls();
        try {
            getAdminClient().setSecurity(acls, null, null, null, newErasePin);
        } catch (KineticException e) {
            fail("set security throw exception: " + e.getMessage());
        }

        byte[] incorrectPin = toByteArray("456");

        try {
            getAdminClient().firmwareDownload(incorrectPin, firmwareInfo);
            getAdminClient().setSecurity(acls, null, null, newErasePin,
                    null);
        } catch (KineticException e) {
            try {
                getAdminClient().setSecurity(acls, null, null, newErasePin,
                        null);
            } catch (KineticException e1) {
                fail("set security throw exception: " + e1.getMessage());
            }
            
            fail("firmware download failed");
        }
    }
}
+150 −183
Original line number Diff line number Diff line
@@ -19,21 +19,20 @@
 */
package com.seagate.kinetic.simulator.client.admin.impl;

import static com.seagate.kinetic.KineticTestHelpers.cleanPin;
import static com.seagate.kinetic.KineticTestHelpers.setDefaultAcls;
import static com.seagate.kinetic.KineticTestHelpers.toByteArray;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import kinetic.admin.ACL;
import kinetic.client.KineticException;

import org.junit.Test;

import com.google.protobuf.ByteString;
import com.seagate.kinetic.IntegrationTestCase;
import com.seagate.kinetic.common.lib.KineticMessage;
import com.seagate.kinetic.proto.Kinetic.Message;
//import com.seagate.kinetic.proto.Kinetic.Message.Setup;
//import com.seagate.kinetic.proto.Kinetic.Message.Status;

/**
 *
@@ -44,181 +43,149 @@ import com.seagate.kinetic.proto.Kinetic.Message;
 *
 */
public class PINTest extends IntegrationTestCase {

    @Test
	public void testSetPin() throws KineticException, IOException,
	InterruptedException {
//		Message.Builder request = Message.newBuilder();
//		Setup.Builder setup = request.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		setup.setNewClusterVersion(0);
//		setup.setInstantSecureErase(false);
//		String setPin = "pin001";
//		setup.setSetPin(ByteString.copyFromUtf8(setPin));
//
//		KineticMessage km = new KineticMessage();
//		km.setMessage(request);
//
//		Message respond = (Message) getAdminClient().configureSetupPolicy(km)
//				.getMessage();
//		assertTrue(respond.getCommand().getStatus().getCode()
//				.equals(Status.StatusCode.SUCCESS));
//
//		cleanPin(setPin, this.getAdminClient());
    public void testSetErasePin() {
        byte[] newErasePin = toByteArray("123");

        List<ACL> acls = new ArrayList<ACL>();
        acls = setDefaultAcls();
        try {
            getAdminClient().setSecurity(acls, null, null, null, newErasePin);
            getAdminClient().setSecurity(acls, null, null, newErasePin, null);
        } catch (KineticException e) {
            fail("set pin throw exception: " + e.getMessage());
        }
    }

    @Test
	public void testModifyOldPin_WithRightOldPin() throws KineticException,
	IOException, InterruptedException {
//		Message.Builder request = Message.newBuilder();
//		Setup.Builder setup = request.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		setup.setNewClusterVersion(0);
//		setup.setInstantSecureErase(false);
//		String firstPin = "pin001";
//		setup.setSetPin(ByteString.copyFromUtf8(firstPin));
//
//		KineticMessage km = new KineticMessage();
//		km.setMessage(request);
//
//		getAdminClient().configureSetupPolicy(km);
//
//		Message.Builder request1 = Message.newBuilder();
//		Setup.Builder setup1 = request1.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		setup1.setNewClusterVersion(0);
//		setup1.setInstantSecureErase(false);
//		String secondPin = "pin002";
//		setup1.setSetPin(ByteString.copyFromUtf8(secondPin));
//		setup1.setPin(ByteString.copyFromUtf8(firstPin));
//
//		KineticMessage km1 = new KineticMessage();
//		km1.setMessage(request1);
//
//		Message respond1 = (Message) getAdminClient().configureSetupPolicy(km1)
//				.getMessage();
//		assertTrue(respond1.getCommand().getStatus().getCode()
//				.equals(Status.StatusCode.SUCCESS));
//
//		cleanPin(secondPin, this.getAdminClient());
    public void testModifyOldPin_WithRightOldPin() {
        byte[] oldErasePin = toByteArray("123");
        byte[] newErasePin = toByteArray("456");

        List<ACL> acls = new ArrayList<ACL>();
        acls = setDefaultAcls();
        try {
            getAdminClient().setSecurity(acls, null, null, null, oldErasePin);
        } catch (KineticException e) {
            fail("set pin throw exception: " + e.getMessage());
        }

        try {
            getAdminClient().setSecurity(acls, null, null, oldErasePin,
                    newErasePin);
        } catch (KineticException e) {
            fail("modify pin throw exception: " + e.getMessage());
        }

        // clean pin
        try {
            getAdminClient().setSecurity(acls, null, null, newErasePin, null);
        } catch (KineticException e) {
            fail("clean pin throw exception: " + e.getMessage());
        }
    }

    @Test
	public void testModifyOldPin_WithWrongOldPin() throws KineticException,
	IOException, InterruptedException {
//		Message.Builder request = Message.newBuilder();
//		Setup.Builder setup = request.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		setup.setNewClusterVersion(0);
//		setup.setInstantSecureErase(false);
//		String firstPin = "pin001";
//		setup.setSetPin(ByteString.copyFromUtf8(firstPin));
//
//		KineticMessage km = new KineticMessage();
//		km.setMessage(request);
//
//		getAdminClient().configureSetupPolicy(km);
//
//		Message.Builder request1 = Message.newBuilder();
//		Setup.Builder setup1 = request1.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		setup1.setNewClusterVersion(0);
//		setup1.setInstantSecureErase(false);
//		setup1.setSetPin(ByteString.copyFromUtf8("pin002"));
//		setup1.setPin(ByteString.copyFromUtf8("pin003"));
//
//		KineticMessage km1 = new KineticMessage();
//		km1.setMessage(request1);
//
//        try {
//            @SuppressWarnings("unused")
//            Message respond1 = (Message) getAdminClient().configureSetupPolicy(
//                    km1).getMessage();
//        } catch (KineticException ke) {
//            assertTrue(ke.getResponseMessage().getMessage().getCommand()
//                    .getStatus().getCode()
//                    .equals(Status.StatusCode.INTERNAL_ERROR));
//        } finally {
//
//            cleanPin(firstPin, this.getAdminClient());
//        }
    public void testModifyOldPin_WithWrongOldPin() {
        byte[] oldErasePin = toByteArray("123");
        byte[] oldIncorrectErasePin = toByteArray("456");
        byte[] newErasePin = toByteArray("789");

        List<ACL> acls = new ArrayList<ACL>();
        acls = setDefaultAcls();
        try {
            getAdminClient().setSecurity(acls, null, null, null, oldErasePin);
        } catch (KineticException e) {
            fail("set pin throw exception: " + e.getMessage());
        }

        try {
            getAdminClient().setSecurity(acls, null, null,
                    oldIncorrectErasePin, newErasePin);
            fail("should throw exception");
        } catch (KineticException e) {
            assertTrue(e.getMessage().contains("NOT_AUTHORIZED"));
        }

        // clean pin
        try {
            getAdminClient().setSecurity(acls, null, null, oldErasePin, null);
        } catch (KineticException e) {
            fail("clean pin throw exception: " + e.getMessage());
        }
    }

    @Test
	public void testModifyOldPinWithRightPin_AfterRestartServer()
			throws Exception {
//		Message.Builder request = Message.newBuilder();
//		Setup.Builder setup = request.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		String firstPin = "pin001";
//		setup.setSetPin(ByteString.copyFromUtf8(firstPin));
//
//		KineticMessage km = new KineticMessage();
//		km.setMessage(request);
//
//		Message respond = (Message) this.getAdminClient()
//				.configureSetupPolicy(km).getMessage();
//		assertTrue(respond.getCommand().getStatus().getCode()
//				.equals(Status.StatusCode.SUCCESS));
//
//		// restart server
//		restartServer();
//
//		Message.Builder request1 = Message.newBuilder();
//		Setup.Builder setup1 = request1.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		String secondPin = "pin002";
//		setup1.setSetPin(ByteString.copyFromUtf8(secondPin));
//		setup1.setPin(ByteString.copyFromUtf8(firstPin));
//
//		KineticMessage km1 = new KineticMessage();
//		km1.setMessage(request1);
//
//		Message respond1 = (Message) getAdminClient().configureSetupPolicy(km1)
//				.getMessage();
//		assertTrue(respond1.getCommand().getStatus().getCode()
//				.equals(Status.StatusCode.SUCCESS));
//
//		cleanPin(secondPin, this.getAdminClient());
    public void testModifyOldPinWithRightPin_AfterRestartServer() {
        byte[] oldErasePin = toByteArray("123");
        byte[] newErasePin = toByteArray("456");

        List<ACL> acls = new ArrayList<ACL>();
        acls = setDefaultAcls();
        try {
            getAdminClient().setSecurity(acls, null, null, null, oldErasePin);
        } catch (KineticException e) {
            fail("set pin throw exception: " + e.getMessage());
        }

        // restart server
        try {
            restartServer();
        } catch (Exception e1) {
            fail("restart server throw exception: " + e1.getMessage());
        }

        try {
            getAdminClient().setSecurity(acls, null, null, oldErasePin,
                    newErasePin);
        } catch (KineticException e) {
            fail("modify pin throw exception: " + e.getMessage());
        }

        // clean pin
        try {
            getAdminClient().setSecurity(acls, null, null, newErasePin, null);
        } catch (KineticException e) {
            fail("clean pin throw exception: " + e.getMessage());
        }
    }

    @Test
	public void testModifyOldPin_WithWrongPin_AfterRestartServer()
			throws Exception {
//		Message.Builder request = Message.newBuilder();
//		Setup.Builder setup = request.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		String firstPin = "pin001";
//		setup.setSetPin(ByteString.copyFromUtf8(firstPin));
//
//		KineticMessage km = new KineticMessage();
//		km.setMessage(request);
//
//		getAdminClient().configureSetupPolicy(km);
//
//		// restart server
//		restartServer();
//
//		Message.Builder request1 = Message.newBuilder();
//		Setup.Builder setup1 = request1.getCommandBuilder().getBodyBuilder()
//				.getSetupBuilder();
//		setup1.setSetPin(ByteString.copyFromUtf8("pin002"));
//		setup1.setPin(ByteString.copyFromUtf8("pin002"));
//
//		KineticMessage km1 = new KineticMessage();
//		km1.setMessage(request1);
//
//        try {
//            @SuppressWarnings("unused")
//            Message respond1 = (Message) getAdminClient().configureSetupPolicy(
//                    km1).getMessage();
//        } catch (KineticException ke) {
//            assertTrue(ke.getResponseMessage().getMessage().getCommand()
//                    .getStatus().getCode()
//                    .equals(Status.StatusCode.INTERNAL_ERROR));
//        } finally {
//            cleanPin(firstPin, this.getAdminClient());
//        }
    public void testModifyOldPin_WithWrongPin_AfterRestartServer() {
        byte[] oldErasePin = toByteArray("123");
        byte[] oldIncorrectErasePin = toByteArray("456");
        byte[] newErasePin = toByteArray("789");

        List<ACL> acls = new ArrayList<ACL>();
        acls = setDefaultAcls();
        try {
            getAdminClient().setSecurity(acls, null, null, null, oldErasePin);
        } catch (KineticException e) {
            fail("set pin throw exception: " + e.getMessage());
        }

        // restart server
        try {
            restartServer();
        } catch (Exception e1) {
            fail("restart server throw exception: " + e1.getMessage());
        }

        try {
            getAdminClient().setSecurity(acls, null, null,
                    oldIncorrectErasePin, newErasePin);
            fail("should throw exception");
        } catch (KineticException e) {
            assertTrue(e.getMessage().contains("NOT_AUTHORIZED"));
        }

        // clean pin
        try {
            getAdminClient().setSecurity(acls, null, null, oldErasePin, null);
        } catch (KineticException e) {
            fail("clean pin throw exception: " + e.getMessage());
        }
    }

}
Loading