Example #1
0
  /** Test password with & and ! characters */
  @Test
  public void testPasswordStrange() throws Exception {

    final String username = "******";
    final String password = "******";
    final String remoteName = "myRemote";

    // specify remote and username
    CommandInvoker commandInvoker =
        getInvoker().argument("username", username).option("--remote", remoteName);

    // set strange password !
    commandInvoker.setSystemIn(password + System.lineSeparator());

    // Mock remote
    CommandSession commandSession = commandInvoker.getCommandSession();
    Mockito.reset(commandSession);
    MultiRemoteCodenvy remoteCodenvy = mock(MultiRemoteCodenvy.class);
    doReturn(remoteCodenvy).when(commandSession).get(MultiRemoteCodenvy.class.getName());
    doReturn(true).when(remoteCodenvy).hasAvailableRemotes();

    // Check we have the same password in input
    doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                Assert.assertEquals(args[0], remoteName);
                Assert.assertEquals(args[1], username);
                Assert.assertEquals(args[2], password);
                return null;
              }
            })
        .when(remoteCodenvy)
        .login(anyString(), anyString(), anyString());

    // invoke command
    commandInvoker.invoke();
  }
Example #2
0
 protected Response act(final CommandInvoker invoker, boolean detached) {
   if (detached) {
     return accepted(invoker.getCommand(), invoker.getParams(), null);
   } else {
     invoker.setResult(
         executeWriteCommand(invoker.getCommand(), invoker.getParams()).getExtraProperties());
     return acted(invoker.getSuccessMessage());
   }
 }
Example #3
0
  protected Response actSse(final CommandInvoker invoker) {
    final boolean includeResourceLinks = includeResourceLinks();
    EventOutput eo =
        executeSseCommand(
            getSubject(),
            invoker.getCommand(),
            invoker.getParams(),
            new ResponseBodyBuilderImpl() {
              @Override
              protected ResponseBody success(ActionReport report) {
                invoker.setResult(report.getExtraProperties());
                SseResponseBody responseBody = new SseResponseBody();
                responseBody.addSuccess(invoker.getSuccessMessage());
                return responseBody;
              }

              @Override
              protected boolean includeResourceLinks() {
                return includeResourceLinks;
              }
            });

    return Response.status(Status.ACCEPTED).entity(eo).build();
  }
  @Before
  public void setUp() throws Exception {
    // Setup Drive
    drive = new Drive("C");
    dirRoot = drive.getRootDirectory();

    // Create Directories
    dirTemp = new Directory("Temp");
    dirWindows = new Directory("Windows");
    dirProgramFiles = new Directory("ProgramFiles");
    dirWindowsSystem32 = new Directory("system32");
    dirWindowsWeb = new Directory("web");
    dirWindowsNet = new Directory("Microsoft.NET");
    dirTestDir1 = new Directory("TestDir1");
    dirTestDir2 = new Directory("TestDir2");
    dirTestDir3 = new Directory("TestDir3");

    // Setup Directory Structure
    dirRoot.add(dirTemp);
    dirRoot.add(dirWindows);
    dirRoot.add(dirProgramFiles);
    dirTemp.add(dirTestDir1);
    dirTemp.add(dirTestDir2);
    dirTestDir2.add(dirTestDir3);
    dirWindows.add(dirWindowsSystem32);
    dirWindows.add(dirWindowsWeb);
    dirWindows.add(dirWindowsNet);

    // Create Files
    fileWinWord = new File("WinWord.exe", "File WinWord.exe");
    fileExcel = new File("Excel.exe", "File Excel.exe");
    fileSkiChallenge = new File("SkiChallenge.exe", "File SkiChallenge.exe");
    fileGaga = new File("gaga.txt", "gaga.txt");
    fileLog = new File("log.log", "log.log");
    fileMyStuff = new File("myStuff.doc", "myStuff.doc");
    fileTest1 = new File("test1.txt", "test1.txt");
    fileTest2 = new File("test2.txt", "test2.txt");
    fileTest3 = new File("test3.txt", "test3.txt");
    fileCommand = new File("command.com", "command.com");
    fileClock = new File("clock.avi", "clock.avi");
    fileExplorer = new File("explorer.exe", "explorer.exe");
    fileTaskman = new File("TASKMAN.exe", "TASKMAN.exe");
    fileWinnt = new File("$winnt$.inf", "$winnt$.inf");
    fileMFC40 = new File("mfc40.dll", "mfc40.dll");
    fileMFC40u = new File("mfc40u.dll", "mfc40u.dll");
    fileMFC42 = new File("mfc42.dll", "mfc42.dll");
    fileBullet = new File("bullet.gif", "bullet.gif");
    fileSbsDiasymreader = new File("sbs_diasymreader.dll", "sbs_diasymreader.dll");
    fileSbsIehost = new File("sbs_iehost.dll", "sbs_iehost.dll");

    // Add files to directory structure
    dirProgramFiles.add(fileWinWord);
    dirProgramFiles.add(fileExcel);
    dirProgramFiles.add(fileSkiChallenge);
    dirTemp.add(fileGaga);
    dirTemp.add(fileLog);
    dirTemp.add(fileMyStuff);
    dirTestDir1.add(fileTest1);
    dirTestDir1.add(fileTest2);
    dirTestDir1.add(fileTest3);
    dirWindows.add(fileCommand);
    dirWindows.add(fileClock);
    dirWindows.add(fileExplorer);
    dirWindows.add(fileTaskman);
    dirWindowsSystem32.add(fileWinnt);
    dirWindowsSystem32.add(fileMFC40);
    dirWindowsSystem32.add(fileMFC40u);
    dirWindowsSystem32.add(fileMFC42);
    dirWindowsNet.add(fileBullet);
    dirWindowsNet.add(fileSbsDiasymreader);
    dirWindowsNet.add(fileSbsIehost);

    // Setup Command Environment
    factory = new CommandFactory(drive);
    histroyDAO = DaoFactory.createHistoryDao(DaoType.FAKE);
    commandInvoker = new CommandInvoker(histroyDAO);
    commandInvoker.setCommands(factory.getCommandList());

    testOutput = new TestOutputter();
  }