Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions zap/src/main/java/org/parosproxy/paros/control/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ public static void initSingletonForTesting(Model model) {
control = new Control(model, null);
}

public static void setSingletonForTesting(Control control) {
Control.control = control;
}

/**
* Initialises the {@code Control} singleton with the given data.
*
Expand Down
2 changes: 1 addition & 1 deletion zap/src/main/java/org/zaproxy/zap/utils/ErrorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public boolean handleDiskSpaceException(Exception e) {
logAndStderr("Shutting down ZAP due to space issues...");
Control control = Control.getSingleton();
control.setExitStatus(2, errorMsg);
control.exit(false, null);
control.exit(true, null);
}
}

Expand Down
15 changes: 15 additions & 0 deletions zap/src/test/java/org/zaproxy/zap/utils/ErrorUtilsUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;

public class ErrorUtilsUnitTest {

Expand Down Expand Up @@ -68,6 +69,20 @@ void shouldHandleDiskSpaceException(String message) {
assertThat(ErrorUtils.getOutOfDiskSpaceHandler().isOutOfSpace(), is(equalTo(true)));
}

@Test
void shouldExitWhenExitOnOutOfSpaceEnabled() {
// Given
Control control = mock();
Control.setSingletonForTesting(control);
Exception e = new Exception("Test", new Exception("Data File size limit is reached"));
ErrorUtils.getOutOfDiskSpaceHandler().setExitOnOutOfSpace(true);
// When
ErrorUtils.handleDiskSpaceException(e);
// Then
verify(control).setExitStatus(2, null);
verify(control).exit(true, null);
}

@Test
void shouldIgnoreNonDiskSpaceException() {
// Given
Expand Down
Loading