|
| 1 | +/** |
| 2 | + * TLS-Attacker - A Modular Penetration Testing Framework for TLS |
| 3 | + * |
| 4 | + * Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + */ |
| 9 | +package de.rub.nds.tlsattacker.core.workflow.action; |
| 10 | + |
| 11 | +import de.rub.nds.tlsattacker.core.config.Config; |
| 12 | +import de.rub.nds.tlsattacker.core.exceptions.WorkflowExecutionException; |
| 13 | +import de.rub.nds.tlsattacker.core.state.State; |
| 14 | +import de.rub.nds.tlsattacker.core.state.TlsContext; |
| 15 | +import de.rub.nds.tlsattacker.core.workflow.WorkflowTrace; |
| 16 | +import java.io.IOException; |
| 17 | +import java.io.StringReader; |
| 18 | +import java.io.StringWriter; |
| 19 | +import java.security.InvalidAlgorithmParameterException; |
| 20 | +import java.security.InvalidKeyException; |
| 21 | +import java.security.NoSuchAlgorithmException; |
| 22 | +import javax.crypto.NoSuchPaddingException; |
| 23 | +import javax.xml.bind.JAXB; |
| 24 | +import org.junit.After; |
| 25 | +import static org.junit.Assert.*; |
| 26 | +import org.junit.Before; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +/** |
| 30 | + * |
| 31 | + * @author Steve Ehleringer - steve.ehleringer@rub.de |
| 32 | + */ |
| 33 | +public class WaitingActionTest { |
| 34 | + |
| 35 | + private State state; |
| 36 | + private TlsContext tlsContext; |
| 37 | + |
| 38 | + private WaitingAction action; |
| 39 | + |
| 40 | + @Before |
| 41 | + public void setUp() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, |
| 42 | + InvalidAlgorithmParameterException { |
| 43 | + Config config = Config.createConfig(); |
| 44 | + state = new State(config, new WorkflowTrace(config)); |
| 45 | + action = new WaitingAction(10); |
| 46 | + } |
| 47 | + |
| 48 | + @After |
| 49 | + public void tearDown() { |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Test of execute method, of class WaitingAction. |
| 54 | + */ |
| 55 | + @Test |
| 56 | + public void testExecute() throws WorkflowExecutionException, IOException { |
| 57 | + long time = System.currentTimeMillis(); |
| 58 | + action.execute(state); |
| 59 | + assertTrue(10l <= System.currentTimeMillis() - time); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Test of reset method, of class WaitingAction. |
| 64 | + */ |
| 65 | + @Test |
| 66 | + public void testReset() throws WorkflowExecutionException, IOException { |
| 67 | + assertFalse(action.isExecuted()); |
| 68 | + action.execute(state); |
| 69 | + assertTrue(action.isExecuted()); |
| 70 | + action.reset(); |
| 71 | + assertFalse(action.isExecuted()); |
| 72 | + action.execute(state); |
| 73 | + assertTrue(action.isExecuted()); |
| 74 | + } |
| 75 | + |
| 76 | + /* |
| 77 | + * Test of JAXB.marshal and JAXB.unmarshal |
| 78 | + */ |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testJAXB() { |
| 82 | + StringWriter writer = new StringWriter(); |
| 83 | + JAXB.marshal(action, writer); |
| 84 | + WaitingAction action2 = JAXB.unmarshal(new StringReader(writer.getBuffer().toString()), WaitingAction.class); |
| 85 | + assertEquals(action.getTime(), action2.getTime()); |
| 86 | + } |
| 87 | + |
| 88 | +} |
0 commit comments