ThresholdState extends AbstractDoSState { @Override public void update( IntelligentDoSLibraryImpl STATE_CONTEXT, AttackModel attackModel ) { CommonParamItem middle; switch ( ths ) { case PARAM: middle = createMiddleForParamItem( minimumParamItem, maximumParamItem ); AttackModel middleParamAttack = createTRWithParam( STATE_CONTEXT, middle ); count++; switchTo( THS.PARAMTHRESHOLD, STATE_CONTEXT, middleParamAttack ); break; case PARAMTHRESHOLD: if ( iteration < ITERATIONS ) { if ( attackModel.isAllFail() ) { if ( count > RESENDS ) { logger.warn( "Further investigation is not possible! " + attackModel.getErrorCount() + " requests has not been send successfully. Abort execution." ); switchToFinishState( STATE_CONTEXT ); } else { middle = attackModel.getParamItem(); AttackModel paramMiddleAttack = createTRWithParam( STATE_CONTEXT, middle ); setAttack( STATE_CONTEXT, paramMiddleAttack ); count++; } } else if ( attackModel.wasAttackExecutionSuccessful() ) { setMinimumParamItem( attackModel.getParamItem() ); middle = createMiddleForParamItem( minimumParamItem, maximumParamItem ); AttackModel paramMiddleAttack = createTRWithParam( STATE_CONTEXT, middle ); setAttack( STATE_CONTEXT, paramMiddleAttack ); iteration++; } else { setMaximumParamItem( attackModel.getParamItem() ); middle = createMiddleForParamItem( minimumParamItem, maximumParamItem ); AttackModel paramMiddleAttack = createTRWithParam( STATE_CONTEXT, middle ); setAttack( STATE_CONTEXT, paramMiddleAttack ); iteration++; } } else { if ( attackModel.isAllFail() ) { setMaximumParamItem( attackModel.getParamItem() ); } else if ( attackModel.wasAttackExecutionSuccessful() ) { setMinimumParamItem( attackModel.getParamItem() ); } STATE_CONTEXT.setMaximumRequestsPerSecond( minimumParamItem.getReuqestsPerSecond() ); STATE_CONTEXT.setDoSState( new TamperedState() ); continueAttacks( STATE_CONTEXT ); resetIteration(); } break; case VALUE: AttackModel middleAttack = createMiddle( STATE_CONTEXT ); switchTo( THS.THRESHOLD, STATE_CONTEXT, middleAttack ); resetIteration(); break; case THRESHOLD: if ( iteration < ITERATIONS ) { if ( attackModel.isAllFail() ) { setMaximumAttack( attackModel ); newFindThresholdIteration( STATE_CONTEXT ); } else if ( attackModel.wasAttackExecutionSuccessful() ) { setMinimumAttack( attackModel ); newFindThresholdIteration( STATE_CONTEXT ); } else { if ( count > RESENDS ) { logger.warn( "Further investigation is not possible! " + attackModel.getErrorCount() + " requests has not been send successfully. Abort execution." ); switchToFinishState( STATE_CONTEXT ); } else { createMiddleAttackAndSetToContext( STATE_CONTEXT ); count++; } } } else { if ( attackModel.isAllFail() ) { setMaximumAttack( attackModel ); } else if ( attackModel.wasAttackExecutionSuccessful() ) { setMinimumAttack( attackModel ); } STATE_CONTEXT.addThreshold( new Threshold( minimumAttack.getDoSAttack(), maximumAttack.getDoSAttack() ) ); continueAttacks( STATE_CONTEXT ); resetIteration(); } break; default: break; } } ThresholdState( CommonParamItem minimumParamItem, CommonParamItem maximumParamItem );  ThresholdState( AttackModel minimumAttack, AttackModel maximumAttack ); @Override String getName(); @Override void update( IntelligentDoSLibraryImpl STATE_CONTEXT, AttackModel attackModel ); @Override void updateTestProbes( Metric metric );  }
@Test public void test() { IntelligentDoSLibraryImpl impl = Mockito.mock( IntelligentDoSLibraryImpl.class ); AttackModel model = new AttackModel(); when( impl.createNewTampered( false ) ).thenReturn( model ); CommonParamItem min = new CommonParamItem( 1, 1, 1000 ); CommonParamItem max = new CommonParamItem( 10, 10, 125 ); ThresholdState thresholdState = new ThresholdState( min, max ); AttackModel attackModel = create( RequestType.TAMPERED, "content" ); thresholdState.update( impl, attackModel ); verify( impl, times( 1 ) ).createNewTampered( false ); attackModel = create( RequestType.TAMPERED, "" ); thresholdState.update( impl, attackModel ); verify( impl, times( 2 ) ).createNewTampered( false ); }