Cyberduck Mountain Duck CLI

Changeset 11463


Ignore:
Timestamp:
Jun 28, 2013 10:24:50 AM (7 years ago)
Author:
dkocher
Message:

Close connection when login is canceled.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/ch/cyberduck/core/ConnectionCheckService.java

    r11416 r11463  
    8383        }
    8484
    85         final Host bookmark = session.getHost();
    86         session.message(MessageFormat.format(Locale.localizedString("Opening {0} connection to {1}", "Status"),
    87                 bookmark.getProtocol().getName(), bookmark.getHostname()));
     85        try {
     86            final Host bookmark = session.getHost();
     87            session.message(MessageFormat.format(Locale.localizedString("Opening {0} connection to {1}", "Status"),
     88                    bookmark.getProtocol().getName(), bookmark.getHostname()));
    8889
    89         // Configuring proxy if any
    90         ProxyFactory.get().configure(bookmark);
     90            // Configuring proxy if any
     91            ProxyFactory.get().configure(bookmark);
    9192
    92         final Resolver resolver = new Resolver(
    93                 HostnameConfiguratorFactory.get(bookmark.getProtocol()).lookup(bookmark.getHostname()));
     93            final Resolver resolver = new Resolver(
     94                    HostnameConfiguratorFactory.get(bookmark.getProtocol()).lookup(bookmark.getHostname()));
    9495
    95         session.message(MessageFormat.format(Locale.localizedString("Resolving {0}", "Status"),
    96                 bookmark.getHostname()));
     96            session.message(MessageFormat.format(Locale.localizedString("Resolving {0}", "Status"),
     97                    bookmark.getHostname()));
    9798
    98         // Try to resolve the hostname first
    99         try {
    100             resolver.resolve();
     99            // Try to resolve the hostname first
     100            try {
     101                resolver.resolve();
     102            }
     103            catch(IOException e) {
     104                throw new DefaultIOExceptionMappingService().map(e);
     105            }
     106            // The IP address could successfully be determined
     107
     108            session.open(key);
     109
     110            GrowlFactory.get().notify("Connection opened", bookmark.getHostname());
     111
     112            session.message(MessageFormat.format(Locale.localizedString("{0} connection opened", "Status"),
     113                    bookmark.getProtocol().getName()));
     114
     115            // Update last accessed timestamp
     116            bookmark.setTimestamp(new Date());
     117
     118            LoginService login = new LoginService(prompt);
     119            login.login(session);
     120
     121            final HistoryCollection history = HistoryCollection.defaultCollection();
     122            history.add(new Host(bookmark.getAsDictionary()));
     123
     124            // Notify changed bookmark
     125            if(BookmarkCollection.defaultCollection().contains(bookmark)) {
     126                BookmarkCollection.defaultCollection().collectionItemChanged(bookmark);
     127            }
    101128        }
    102         catch(IOException e) {
    103             throw new DefaultIOExceptionMappingService().map(e);
    104         }
    105         // The IP address could successfully be determined
    106 
    107         session.open(key);
    108 
    109         GrowlFactory.get().notify("Connection opened", bookmark.getHostname());
    110 
    111         session.message(MessageFormat.format(Locale.localizedString("{0} connection opened", "Status"),
    112                 bookmark.getProtocol().getName()));
    113 
    114         // Update last accessed timestamp
    115         bookmark.setTimestamp(new Date());
    116 
    117         LoginService login = new LoginService(prompt);
    118         login.login(session);
    119 
    120         final HistoryCollection history = HistoryCollection.defaultCollection();
    121         history.add(new Host(bookmark.getAsDictionary()));
    122 
    123         // Notify changed bookmark
    124         if(BookmarkCollection.defaultCollection().contains(bookmark)) {
    125             BookmarkCollection.defaultCollection().collectionItemChanged(bookmark);
     129        catch(ConnectionCanceledException e) {
     130            session.close();
     131            throw e;
    126132        }
    127133    }
  • trunk/test/ch/cyberduck/core/ConnectionCheckServiceTest.java

    r11316 r11463  
    2121    public void testCheckUnknown() throws Exception {
    2222        ConnectionCheckService s = new ConnectionCheckService(new DisabledLoginController(), new DefaultHostKeyController());
     23        final FTPSession session = new FTPSession(new Host("unknownhost.local"));
    2324        try {
    24             s.check(new FTPSession(new Host("unknownhost.local")));
     25            s.check(session);
    2526        }
    2627        catch(BackgroundException e) {
    2728            assertEquals(UnknownHostException.class, e.getCause().getClass());
     29            assertEquals(Session.State.closed, session.getState());
    2830            throw e;
    2931        }
     
    3234    @Test(expected = ConnectionCanceledException.class)
    3335    public void testHandshakeFailure() throws Exception {
     36        final DAVSession session = new DAVSession(new Host(Protocol.WEBDAV_SSL, "54.228.253.92", new Credentials("user", "p")));
    3437        KeychainFactory.addFactory(Factory.NATIVE_PLATFORM, new KeychainFactory() {
    3538            @Override
    3639            protected AbstractKeychain create() {
    37                 return new NoTrustKeychain();
     40                return new NullKeychain() {
     41                    @Override
     42                    public boolean isTrusted(final String hostname, final X509Certificate[] certs) {
     43                        return false;
     44                    }
     45                };
    3846            }
    3947        });
     
    5664        });
    5765        ConnectionCheckService s = new ConnectionCheckService(new DisabledLoginController(), new DefaultHostKeyController());
    58         s.check(new DAVSession(new Host(Protocol.WEBDAV_SSL, "54.228.253.92", new Credentials("user", "p"))));
     66        s.check(session);
    5967    }
    6068
     
    6472        s.check(new FTPSession(new Host("")));
    6573    }
    66 
    67     private final class NoTrustKeychain extends NullKeychain {
    68         @Override
    69         public boolean isTrusted(final String hostname, final X509Certificate[] certs) {
    70             return false;
    71         }
    72     }
    7374}
Note: See TracChangeset for help on using the changeset viewer.
swiss made software