@Test public void testGetCommandTokenNotModifySH() throws Exception { String cmd = "sh -c 'ps -ef | grep firefox | grep -v grep'"; String[] parsed = Utils.getCommandTokens(cmd); Iterator<String> it = Arrays.asList(parsed).iterator(); Assert.assertEquals(it.next(), "sh"); Assert.assertEquals(it.next(), "-c"); Assert.assertEquals(it.next(), "ps -ef | grep firefox | grep -v grep"); Assert.assertEquals(CommandLine.parse(cmd).getArguments()[1], "\"ps -ef | grep firefox | grep -v grep\""); }
@Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; } }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }  }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }  @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString); @AfterThrowing(pointcut = "execution(* net.sf.sahi.util.Utils.execute*(..))", throwing = "error") void catchSahiCommandExcecutionErrors(JoinPoint joinPoint, Exception error); @Before("execution(* net.sf.sahi.util.Utils.execute*(..))") void logSahiCommandExection(JoinPoint joinPoint); }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }  @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString); @AfterThrowing(pointcut = "execution(* net.sf.sahi.util.Utils.execute*(..))", throwing = "error") void catchSahiCommandExcecutionErrors(JoinPoint joinPoint, Exception error); @Before("execution(* net.sf.sahi.util.Utils.execute*(..))") void logSahiCommandExection(JoinPoint joinPoint);  }