@Test void createFrom_invalid_invalidServerConfigSettings() { MockConfigPart data = new MockConfigPart() .withUsername("u") .withServerName("blah") .withClientname("c"); ServerConfig sc = ServerConfig.createFrom(data); data.withUsername(null).withServerName(null); // Should not throw an error - it only needs client stuff. ClientConfig.createFrom(sc, data); }
private static MockConfigPart createConfigPart() { return new MockConfigPart() // By using the RSH port, it means that the connection will be kept open // (NTS connection). By keeping the connection open until explicitly // disconnected, this will indirectly be testing that the // SimpleConnectionManager closes the connection. .withServerName("1234") .withUsername("u") .withNoPassword() .withClientname("client1"); }
public ClientConfigRoot addClientConfigRoot(TemporaryFolder tmp, String clientRootDir) { File base = tmp.newFile(clientRootDir); if (!base.mkdirs()) { throw new RuntimeException("Could not create directory " + base); } MockConfigPart cp1 = new MockConfigPart() .withClientname("cn") .withUsername("u") .withServerName("s:123"); ClientConfig cc = ClientConfig.createFrom(ServerConfig.createFrom(cp1), cp1); FilePath fp = VcsUtil.getFilePath(base); VirtualFile rootDir = Objects.requireNonNull(fp.getVirtualFile()); registry.addClientConfig(cc, rootDir); roots.add(rootDir); return Objects.requireNonNull(registry.getClientFor(rootDir)); }
private ClientConfig createClientConfig(String clientName) { MockConfigPart data = new MockConfigPart() .withServerName("1666") .withUsername("user") .withClientname(clientName); ServerConfig serverConfig = ServerConfig.createFrom(data); return ClientConfig.createFrom(serverConfig, data); } }
@Test void getServerIdForDataPart_full() { MockConfigPart data = new MockConfigPart() .withServerName("1234") .withUsername("luser") .withPassword("my password") .withAuthTicketFile(new File("auth-ticket-file")) .withTrustTicketFile(new File("trust-ticket-file")) .withServerFingerprint("1234asdf1234asdf"); assertEquals("localhost:1234" + SEP + "luser" + SEP + "auth-ticket-file" + SEP + "trust-ticket-file" + SEP + "1234asdf1234asdf", ServerConfig.getServerIdForDataPart(data)); }
@Test void createFrom_invalid_noClientname() { MockConfigPart data = new MockConfigPart() .withUsername("u") .withServerName("blah"); assertThrows(IllegalArgumentException.class, () -> ClientConfig.createFrom( ServerConfig.createFrom(data), data )); }
private ClientConfig createClientConfig() { MockConfigPart part = new MockConfigPart() // By using the RSH port, it means that the connection will be kept open // (NTS connection). By keeping the connection open until explicitly // disconnected, this will indirectly be testing that the // SimpleConnectionManager closes the connection. .withServerName(p4.getPort()) .withUsername(p4.getUser()) .withClientname("client") .withNoPassword(); final ServerConfig serverConfig = ServerConfig.createFrom(part); return ClientConfig.createFrom(serverConfig, part); } }
@Test void createFrom_invalid_errors() { MockConfigPart data = new MockConfigPart() .withServerName("blah") .withUsername("u") .withClientname("c"); ServerConfig sc = ServerConfig.createFrom(data); data.withConfigProblems(createError()); assertThrows(IllegalArgumentException.class, () -> ClientConfig.createFrom( sc, data )); }
@Test void toProperties_ServerConfig_empty() { Map<String, String> props = ConfigPropertiesUtil.toProperties( ServerConfig.createFrom( new MockConfigPart() .withUsername("username") .withServerName("servername") ), "<unset>", "<stored>", "<ns>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", portName("servername")), new Pair<>("P4USER", "username"), new Pair<>("P4PASSWD", "<ns>"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>") )); }
@Test void isValid() { assertFalse(ServerConfig.isValidServerConfig(null)); MockConfigPart part = new MockConfigPart(); part.withConfigProblems(createError()); assertFalse(ServerConfig.isValidServerConfig(part)); part.withConfigProblems(); assertFalse(ServerConfig.isValidServerConfig(part)); P4ServerName mockName = mock(P4ServerName.class); when(mockName.getFullPort()).thenReturn(""); part.withP4ServerName(mockName); assertFalse(ServerConfig.isValidServerConfig(part)); part.withConfigProblems(createWarning()) .withServerName("my-server"); assertFalse(ServerConfig.isValidServerConfig(part)); part.withUsername(""); assertFalse(ServerConfig.isValidServerConfig(part)); part.withUsername("abc"); assertTrue(ServerConfig.isValidServerConfig(part)); }
@Test void toProperties_ServerConfig_emptyPassword() { Map<String, String> props = ConfigPropertiesUtil.toProperties( ServerConfig.createFrom( new MockConfigPart() .withUsername("username") .withServerName("servername") .withPassword("") ), "<unset>", "<stored>", "<ns>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", portName("servername")), new Pair<>("P4USER", "username"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>"), // The user supplied an empty password. This means that a password is stored. new Pair<>("P4PASSWD", "<stored>") )); }
@Test void toProperties_ClientConfig_empty() { MockConfigPart part = new MockConfigPart() .withUsername("username") .withServerName("servername") .withClientname("client"); Map<String, String> props = ConfigPropertiesUtil.toProperties( ClientConfig.createFrom(ServerConfig.createFrom(part), part), "<unset>", "<stored>", "<ns>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", portName("servername")), new Pair<>("P4CLIENT", "client"), new Pair<>("P4USER", "username"), new Pair<>("P4PASSWD", "<ns>"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4CHARSET", "<unset>"), new Pair<>("P4IGNORE", "<unset>"), new Pair<>("P4HOST", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>") )); }
.withClientname("cn") .withUsername("u") .withServerName("s:123"); ClientConfig cc1 = ClientConfig.createFrom(ServerConfig.createFrom(cp1), cp1); registry.addClientConfig(cc1, one.getParent()); .withClientname("cn0") .withUsername("u0") .withServerName("s:123"); ClientConfig cc2 = ClientConfig.createFrom(ServerConfig.createFrom(cp2), cp2); registry.addClientConfig(cc2, two.getParent());
.withUsername("username") .withPassword("pass") .withServerName("servername") .withClientname("client") .withTrustTicketFile(trustFile)
.withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword()
@Test void isSameServer_empty() { MockConfigPart part1 = new MockConfigPart() .withUsername("u1") .withServerName("n1:1"); ServerConfig sc = ServerConfig.createFrom(part1); assertTrue(sc.isSameServerConnection(part1)); // Change it in the client ways, and it's still the same server. part1.withClientHostname("h1").withClientname("cc") .withDefaultCharset("a1").withIgnoreFileName("i") .withReloadValue(false); assertTrue(sc.isSameServerConnection(part1)); // Change the user MockConfigPart part2 = part1.copy() .withUsername("u2"); assertFalse(sc.isSameServerConnection(part2)); // change the server name MockConfigPart part3 = part1.copy() .withServerName("n2:1"); assertFalse(sc.isSameServerConnection(part3)); // change the password MockConfigPart part4 = part1.copy() .withPassword("a"); assertFalse(sc.isSameServerConnection(part4)); part4.withNoPassword().withRequiresUserEnteredPassword(true); assertFalse(sc.isSameServerConnection(part4)); }
.withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword()
.withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword()
MockConfigPart data = new MockConfigPart() .withUsername("luser") .withServerName("mine:1234") .withClientname("lclient")
@Test void createFrom_empty() { ServerConfig sc = ServerConfig.createFrom( new MockConfigPart() .withUsername("username") .withServerName("servername") ); assertEquals(P4ServerName.forPort("servername"), sc.getServerName()); assertEquals("username", sc.getUsername()); assertNull(sc.getServerFingerprint()); assertNull(sc.getAuthTicket()); assertNull(sc.getTrustTicket()); assertNull(sc.getLoginSso()); assertThat(sc.getConfigVersion(), greaterThan(0)); assertFalse(sc.hasServerFingerprint()); assertFalse(sc.hasAuthTicket()); assertFalse(sc.hasTrustTicket()); assertFalse(sc.hasLoginSso()); assertFalse(sc.usesStoredPassword()); assertEquals("localhost:servername" + SEP + "username" + SEP + "null" + SEP + "null" + SEP + "null", sc.getServerId()); }