PossibleState extends AbstractDoSState { @Override public void update( IntelligentDoSLibraryImpl STATE_CONTEXT, AttackModel attackModel ) { switch ( verify ) { case NONE: reference = attackModel; if ( attackModel.isAllSOAPFault() ) { AttackModel min = createMinimalUntampered( STATE_CONTEXT ); setAttack( STATE_CONTEXT, min ); } else { createUTR( STATE_CONTEXT ); } count++; verify = NPS.SERVICE_DOWN; break; case SERVICE_DOWN: verifyServiceDown( STATE_CONTEXT, attackModel ); break; case REVALIDATE: revalidateAttackFails( STATE_CONTEXT, attackModel ); break; case PARAM: if ( attackModel.isAllFail() ) { AttackModel minimalAttack = createMinimalDoSAttack( STATE_CONTEXT ); switchTo( NPS.POSSIBLE, STATE_CONTEXT, minimalAttack ); } else { ThresholdState thresholdState = new ThresholdState( attackModel.getParamItem(), reference.getParamItem() ); STATE_CONTEXT.setDoSState( thresholdState ); STATE_CONTEXT.update( attackModel ); } break; case POSSIBLE: if ( attackModel.isAllFail() ) { STATE_CONTEXT.addNotPossible( attackModel.getDoSAttack() ); continueAttacks( STATE_CONTEXT ); } else if ( !attackModel.wasAttackExecutionSuccessful() ) { if ( count > RESENDS ) { logger.warn( "Further investigation is not possible! " + attackModel.getErrorCount() + " requests has not been send successfully. Abort execution." ); switchToFinishState( STATE_CONTEXT ); } else { AttackModel minimalAttack = createMinimalDoSAttack( STATE_CONTEXT ); setAttack( STATE_CONTEXT, minimalAttack ); count++; } } else { ThresholdState thresholdState = new ThresholdState( attackModel, reference ); STATE_CONTEXT.setDoSState( thresholdState ); STATE_CONTEXT.update( attackModel ); } break; default: break; } }  @Override String getName(); @Override void update( IntelligentDoSLibraryImpl STATE_CONTEXT, AttackModel attackModel ); @Override void updateTestProbes( Metric metric );  }
@Test public void notPossibleTest() { IntelligentDoSLibraryImpl impl = Mockito.mock( IntelligentDoSLibraryImpl.class ); AttackModel attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewUntampered( true ); attackModel = create( RequestType.UNTAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl ).setDoSState( org.mockito.Matchers.any( FinishState.class ) ); }
@Test public void soapFaultTest() { IntelligentDoSLibraryImpl impl = Mockito.mock( IntelligentDoSLibraryImpl.class ); AttackModel attackModel = create( RequestType.TAMPERED, "Fault>" ); DoSAttack doSAttack = mock( DoSAttack.class ); attackModel.setDoSAttack( doSAttack ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewUntampered( null ); attackModel = create( RequestType.UNTAMPERED, "Fault>" ); notPossibleState.update( impl, attackModel ); verify( impl ).setDoSState( org.mockito.Matchers.any( FinishState.class ) ); }
@Test public void revalidateOkTest() { IntelligentDoSLibraryImpl impl = Mockito.mock( IntelligentDoSLibraryImpl.class ); AttackModel attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewUntampered( true ); attackModel = create( RequestType.UNTAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewTampered( true ); attackModel = create( RequestType.TAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 2 ) ).createNewTampered( true ); attackModel = create( RequestType.TAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl ).setDoSState( org.mockito.Matchers.any( TamperedState.class ) ); }
@Test public void minimalParamTest() { IntelligentDoSLibraryImpl impl = Mockito.mock( IntelligentDoSLibraryImpl.class ); AttackModel value = new AttackModel(); when( impl.createNewTampered( false ) ).thenReturn( value ); AttackModel attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewUntampered( true ); attackModel = create( RequestType.UNTAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewTampered( true ); attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl ).createNewTampered( false ); verify( impl ).createNewTampered( true ); assertThat( value.getParamItem().getNumberOfRequests(), is( 1 ) ); assertThat( value.getParamItem().getNumberOfThreads(), is( 1 ) ); assertThat( value.getParamItem().getMilliesBetweenRequests(), is( 1000 ) ); attackModel = create( RequestType.TAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl ).setDoSState( org.mockito.Matchers.any( ThresholdState.class ) ); }
@Test public void attackNotPossibleTest() { IntelligentDoSLibraryImpl impl = Mockito.mock( IntelligentDoSLibraryImpl.class ); AttackModel value = new AttackModel(); when( impl.createNewTampered( false ) ).thenReturn( value ); when( impl.getCurrentAttack() ).thenReturn( value ); DoSAttack doSAttack = mock( DoSAttack.class ); AttackModel attackModel = create( RequestType.TAMPERED, "" ); attackModel.setDoSAttack( doSAttack ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewUntampered( true ); attackModel = create( RequestType.UNTAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewTampered( true ); attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewTampered( false ); verify( impl, times( 1 ) ).createNewTampered( true ); assertThat( value.getParamItem().getNumberOfRequests(), is( 1 ) ); assertThat( value.getParamItem().getNumberOfThreads(), is( 1 ) ); assertThat( value.getParamItem().getMilliesBetweenRequests(), is( 1000 ) ); attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl ).createNewTampered( org.mockito.Matchers.any( DoSAttack.class ) ); attackModel = create( RequestType.TAMPERED, "" ); value.setRequestType( RequestType.UNTAMPERED ); notPossibleState.update( impl, attackModel ); verify( impl ).addNotPossible( org.mockito.Matchers.any( DoSAttack.class ) ); verify( impl ).setDoSState( org.mockito.Matchers.any( UntamperedState.class ) ); }
@Test public void attackPossibleTest() { IntelligentDoSLibraryImpl impl = Mockito.mock( IntelligentDoSLibraryImpl.class ); AttackModel value = new AttackModel(); when( impl.createNewTampered( false ) ).thenReturn( value ); when( impl.getCurrentAttack() ).thenReturn( value ); DoSAttack doSAttack = mock( DoSAttack.class ); AttackModel attackModel = create( RequestType.TAMPERED, "" ); attackModel.setDoSAttack( doSAttack ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewUntampered( true ); attackModel = create( RequestType.UNTAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewTampered( true ); attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl ).createNewTampered( false ); verify( impl ).createNewTampered( true ); assertThat( value.getParamItem().getNumberOfRequests(), is( 1 ) ); assertThat( value.getParamItem().getNumberOfThreads(), is( 1 ) ); assertThat( value.getParamItem().getMilliesBetweenRequests(), is( 1000 ) ); attackModel = create( RequestType.TAMPERED, "" ); notPossibleState.update( impl, attackModel ); verify( impl ).createNewTampered( org.mockito.Matchers.any( DoSAttack.class ) ); attackModel = create( RequestType.TAMPERED, "content" ); notPossibleState.update( impl, attackModel ); verify( impl ).setDoSState( org.mockito.Matchers.any( ThresholdState.class ) ); }