Skip to content

Commit

Permalink
Add test for #8463..
Browse files Browse the repository at this point in the history
Former-commit-id: a06093ab35ec29b1543f6e09bdb08909ce5de0b1
  • Loading branch information
dkocher committed Jan 15, 2015
1 parent aa24698 commit 7981b31
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions test/ch/cyberduck/core/LoginConnectionServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import ch.cyberduck.core.dav.DAVSession;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.ConnectionCanceledException;
import ch.cyberduck.core.exception.LoginCanceledException;
import ch.cyberduck.core.exception.LoginFailureException;
import ch.cyberduck.core.ftp.FTPProtocol;
import ch.cyberduck.core.ftp.FTPSession;
import ch.cyberduck.core.sftp.SFTPProtocol;
import ch.cyberduck.core.sftp.SFTPSession;
import ch.cyberduck.core.ssl.CertificateStoreX509TrustManager;
import ch.cyberduck.core.ssl.TrustManagerHostnameCallback;
import ch.cyberduck.core.threading.CancelCallback;

import org.junit.Test;

Expand All @@ -18,8 +23,9 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.schmizz.sshj.SSHClient;

import static org.junit.Assert.*;

/**
* @version $Id$
Expand Down Expand Up @@ -97,4 +103,60 @@ public void interrupt() throws BackgroundException {
assertTrue(disconnected.get());
}
}

@Test(expected = LoginCanceledException.class)
public void testPasswordChange() throws Exception {
final AtomicBoolean connected = new AtomicBoolean();
final AtomicBoolean keychain = new AtomicBoolean();
final AtomicBoolean prompt = new AtomicBoolean();
final LoginConnectionService s = new LoginConnectionService(new DisabledLoginCallback() {
@Override
public void prompt(final Protocol protocol, final Credentials credentials, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
// New password entered
credentials.setPassword("b");
prompt.set(true);
}
}, new DisabledHostKeyCallback(), new DisabledPasswordStore() {
@Override
public String find(final Host host) {
keychain.set(true);
// Old password stored
return "a";
}
}, new DisabledProgressListener(), new DisabledTranscriptListener());
final Host host = new Host(new SFTPProtocol(), "localhost", new Credentials("user", ""));
final Session session = new SFTPSession(host) {

@Override
public SSHClient connect(final HostKeyCallback key) throws BackgroundException {
connected.set(true);
return null;
}

@Override
public boolean isConnected() {
return connected.get();
}

@Override
public void login(final PasswordStore p, final LoginCallback l, final CancelCallback cancel, final Cache<Path> cache) throws BackgroundException {
if(prompt.get()) {
assertEquals("b", host.getCredentials().getPassword());
throw new LoginCanceledException();
}
if(keychain.get()) {
assertFalse(prompt.get());
assertEquals("a", host.getCredentials().getPassword());
throw new LoginFailureException("f");
}
}
};
try {
s.check(session, Cache.<Path>empty());
}
finally {
assertTrue(keychain.get());
assertTrue(prompt.get());
}
}
}

0 comments on commit 7981b31

Please sign in to comment.