add tests

This commit is contained in:
Sebastian Stenzel
2026-03-11 21:05:14 +01:00
parent d15731d5a4
commit 232e6fbf71
2 changed files with 56 additions and 6 deletions

View File

@@ -0,0 +1,47 @@
package org.cryptomator.ui.keyloading.hub;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mockito;
import java.util.Set;
class CheckHostAuthenticityControllerTest {
@ParameterizedTest
@CsvSource({
"https://auth.example.com, https://hub.example.com, true",
"https://hub.example.com, https://hub.example.com, true",
"https://auth.example.com, https://auth.example.com, true",
"https://auth.example.com, https://wrong.example.com, false",
"https://wrong.example.com, https://wrong.example.com, false"
})
void testContainsAllowedHosts(String apiBase, String authEndpoint, boolean expectedResult) {
var hubConfig = new HubConfig();
hubConfig.apiBaseUrl = apiBase;
hubConfig.authEndpoint = authEndpoint;
var controller = new CheckHostAuthenticityController(Mockito.mock(), hubConfig, Mockito.mock(), Mockito.mock(), Mockito.mock(), Mockito.mock(), Mockito.mock());
var actualResult = controller.containsAllowedHosts(Set.of("https://auth.example.com", "https://hub.example.com"));
Assertions.assertEquals(expectedResult, actualResult);
}
@ParameterizedTest
@CsvSource({
"https://example.com, https://example.com",
"https://example.com/foo/bar, https://example.com",
"https://example.com:8080, https://example.com:8080",
"https://user@example.com:8080/foo/bar, https://example.com:8080",
"https://user@example.com:443/foo/bar, https://example.com",
"http://user@example.com:80/foo/bar?foo=bar, http://example.com",
"http://user@example.com:8080/foo/bar?foo=bar, http://example.com:8080"
})
void testGetAuthority(String input, String expected) {
var actual = CheckHostAuthenticityController.getAuthority(input);
Assertions.assertEquals(expected, actual);
}
}