Search in sources :

Example 26 with SVNException

use of org.tmatesoft.svn.core.SVNException in project intellij-community by JetBrains.

the class SvnAuthenticationTest method testWhenAuthCredsNoInServers.

public void testWhenAuthCredsNoInServers() throws Exception {
    final TestListener listener = new TestListener(mySynchObject);
    myAuthenticationManager.addListener(listener);
    final SavedOnceListener savedOnceListener = new SavedOnceListener();
    myAuthenticationManager.addListener(savedOnceListener);
    final File servers = new File(myConfiguration.getConfigurationDirectory(), "servers");
    final File oldServers = new File(myConfiguration.getConfigurationDirectory(), "config_old");
    FileUtil.copy(servers, oldServers);
    try {
        FileUtil.appendToFile(servers, "\nstore-auth-creds=no\n");
        final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");
        final SVNException[] exception = new SVNException[1];
        final Boolean[] result = new Boolean[1];
        synchronousBackground(() -> {
            try {
                listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
                listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
                commonScheme(url, false, null);
                Assert.assertEquals(2, listener.getCnt());
                Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
                myTestInteraction.reset();
                savedOnceListener.assertForAwt();
                savedOnceListener.reset();
                SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
                listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
                listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
                commonScheme(url, false, null);
                Assert.assertEquals(4, listener.getCnt());
                Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
            } catch (SVNException e) {
                exception[0] = e;
            }
            result[0] = true;
        });
        Assert.assertTrue(result[0]);
        Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
        Assert.assertEquals(4, listener.getCnt());
        listener.assertForAwt();
        savedOnceListener.assertForAwt();
        savedOnceListener.assertNotSaved(url, ISVNAuthenticationManager.PASSWORD);
        if (exception[0] != null) {
            throw exception[0];
        }
    } finally {
        FileUtil.delete(servers);
        FileUtil.rename(oldServers, servers);
    }
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) SVNException(org.tmatesoft.svn.core.SVNException) SVNConfigFile(org.tmatesoft.svn.core.internal.wc.SVNConfigFile) File(java.io.File)

Example 27 with SVNException

use of org.tmatesoft.svn.core.SVNException in project intellij-community by JetBrains.

the class SvnAuthenticationTest method testWhenPassSaveNoInConfig.

public void testWhenPassSaveNoInConfig() throws Exception {
    final TestListener listener = new TestListener(mySynchObject);
    myAuthenticationManager.addListener(listener);
    final SavedOnceListener savedOnceListener = new SavedOnceListener();
    myAuthenticationManager.addListener(savedOnceListener);
    final File config = new File(myConfiguration.getConfigurationDirectory(), "config");
    final String contents = FileUtil.loadFile(config);
    final String auth = "[auth]";
    final int idx = contents.indexOf(auth);
    Assert.assertTrue(idx != -1);
    final String newContents = contents.substring(0, idx + auth.length()) + "\nstore-passwords=no\n" + contents.substring(idx + auth.length());
    final File oldConfig = new File(myConfiguration.getConfigurationDirectory(), "config_old");
    FileUtil.rename(config, oldConfig);
    try {
        config.createNewFile();
        FileUtil.appendToFile(config, newContents);
        final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");
        final SVNException[] exception = new SVNException[1];
        final Boolean[] result = new Boolean[1];
        synchronousBackground(() -> {
            try {
                listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
                listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
                listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save));
                commonScheme(url, false, null);
                Assert.assertEquals(3, listener.getCnt());
                Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
                myTestInteraction.reset();
                savedOnceListener.assertForAwt();
                savedOnceListener.reset();
                SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
                listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
                listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
                listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save));
                commonScheme(url, false, null);
                Assert.assertEquals(6, listener.getCnt());
                Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
            } catch (SVNException e) {
                exception[0] = e;
            }
            result[0] = true;
        });
        Assert.assertTrue(result[0]);
        Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
        Assert.assertEquals(6, listener.getCnt());
        listener.assertForAwt();
        savedOnceListener.assertForAwt();
        savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);
        if (exception[0] != null) {
            throw exception[0];
        }
    } finally {
        FileUtil.delete(config);
        FileUtil.rename(oldConfig, config);
    }
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) SVNException(org.tmatesoft.svn.core.SVNException) SVNConfigFile(org.tmatesoft.svn.core.internal.wc.SVNConfigFile) File(java.io.File)

Example 28 with SVNException

use of org.tmatesoft.svn.core.SVNException in project intellij-community by JetBrains.

the class SvnAuthenticationTest method testPlaintextSSLPrompt.

public void testPlaintextSSLPrompt() throws Exception {
    SVNJNAUtil.setJNAEnabled(false);
    // yes, no
    final TestListener listener = new TestListener(mySynchObject);
    myAuthenticationManager.addListener(listener);
    final SavedOnceListener savedOnceListener = new SavedOnceListener();
    myAuthenticationManager.addListener(savedOnceListener);
    myTestInteraction.setSSLPlaintextAnswer(true);
    final SVNURL url = SVNURL.parseURIEncoded("https://some.host.com/repo");
    final SVNException[] exception = new SVNException[1];
    final Boolean[] result = new Boolean[1];
    synchronousBackground(() -> {
        try {
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save));
            commonScheme(url, false, null);
            long start = System.currentTimeMillis();
            waitListenerStep(start, listener, 3);
            Assert.assertEquals(1, myTestInteraction.getNumSSLPlaintextPrompt());
            savedOnceListener.assertSaved(url, ISVNAuthenticationManager.SSL);
            savedOnceListener.reset();
            myTestInteraction.reset();
            UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
                try {
                    clearAuthCache();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });
            myTestInteraction.setSSLPlaintextAnswer(false);
            SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save));
            commonScheme(url, false, null);
            start = System.currentTimeMillis();
            waitListenerStep(start, listener, 6);
            Assert.assertEquals(1, myTestInteraction.getNumSSLPlaintextPrompt());
            SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
            myTestInteraction.reset();
            savedOnceListener.reset();
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save));
            commonScheme(url, false, null);
            start = System.currentTimeMillis();
            waitListenerStep(start, listener, 9);
            Assert.assertEquals(1, myTestInteraction.getNumSSLPlaintextPrompt());
        } catch (SVNException e) {
            exception[0] = e;
        }
        result[0] = true;
    });
    Assert.assertTrue(result[0]);
    Assert.assertEquals(1, myTestInteraction.getNumSSLPlaintextPrompt());
    Assert.assertEquals(9, listener.getCnt());
    listener.assertForAwt();
    savedOnceListener.assertForAwt();
    savedOnceListener.assertSaved(url, ISVNAuthenticationManager.SSL);
    if (exception[0] != null) {
        throw exception[0];
    }
    SVNJNAUtil.setJNAEnabled(true);
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) SVNException(org.tmatesoft.svn.core.SVNException) SVNException(org.tmatesoft.svn.core.SVNException)

Example 29 with SVNException

use of org.tmatesoft.svn.core.SVNException in project intellij-community by JetBrains.

the class SvnAuthenticationTest method testPlaintextPrompt.

public void testPlaintextPrompt() throws Exception {
    SVNJNAUtil.setJNAEnabled(false);
    // yes, no
    final TestListener listener = new TestListener(mySynchObject);
    myAuthenticationManager.addListener(listener);
    final SavedOnceListener savedOnceListener = new SavedOnceListener();
    myAuthenticationManager.addListener(savedOnceListener);
    myTestInteraction.setPlaintextAnswer(true);
    final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");
    final SVNException[] exception = new SVNException[1];
    final Boolean[] result = new Boolean[1];
    synchronousBackground(() -> {
        try {
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save));
            commonScheme(url, false, null);
            long start = System.currentTimeMillis();
            waitListenerStep(start, listener, 3);
            Assert.assertEquals(1, myTestInteraction.getNumPlaintextPrompt());
            savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);
            savedOnceListener.reset();
            myTestInteraction.reset();
            UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
                try {
                    clearAuthCache();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });
            myTestInteraction.setPlaintextAnswer(false);
            SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save));
            commonScheme(url, false, null);
            start = System.currentTimeMillis();
            waitListenerStep(start, listener, 6);
            Assert.assertEquals(1, myTestInteraction.getNumPlaintextPrompt());
            savedOnceListener.reset();
            myTestInteraction.reset();
            SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
            listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save));
            commonScheme(url, false, null);
            start = System.currentTimeMillis();
            waitListenerStep(start, listener, 9);
            Assert.assertEquals(1, myTestInteraction.getNumPlaintextPrompt());
        } catch (SVNException e) {
            exception[0] = e;
        }
        result[0] = true;
    });
    Assert.assertTrue(result[0]);
    Assert.assertEquals(1, myTestInteraction.getNumPlaintextPrompt());
    Assert.assertEquals(9, listener.getCnt());
    listener.assertForAwt();
    savedOnceListener.assertForAwt();
    savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);
    if (exception[0] != null) {
        throw exception[0];
    }
    SVNJNAUtil.setJNAEnabled(true);
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) SVNException(org.tmatesoft.svn.core.SVNException) SVNException(org.tmatesoft.svn.core.SVNException)

Example 30 with SVNException

use of org.tmatesoft.svn.core.SVNException in project intellij-community by JetBrains.

the class CmdStatusClient method createStatusCallback.

public static SvnStatusHandler.ExternalDataCallback createStatusCallback(final StatusConsumer handler, final File base, final Info infoBase, final SvnStatusHandler[] svnHandl) {
    final Map<File, Info> externalsMap = new HashMap<>();
    final String[] changelistName = new String[1];
    return new SvnStatusHandler.ExternalDataCallback() {

        @Override
        public void switchPath() {
            final PortableStatus pending = svnHandl[0].getPending();
            pending.setChangelistName(changelistName[0]);
            try {
                //if (infoBase != null) {
                Info baseInfo = infoBase;
                File baseFile = base;
                final File pendingFile = new File(pending.getPath());
                if (!externalsMap.isEmpty()) {
                    for (File file : externalsMap.keySet()) {
                        if (FileUtil.isAncestor(file, pendingFile, false)) {
                            baseInfo = externalsMap.get(file);
                            baseFile = file;
                            break;
                        }
                    }
                }
                if (baseInfo != null) {
                    final String append;
                    final String systemIndependentPath = FileUtil.toSystemIndependentName(pending.getPath());
                    if (pendingFile.isAbsolute()) {
                        final String relativePath = FileUtil.getRelativePath(FileUtil.toSystemIndependentName(baseFile.getPath()), systemIndependentPath, '/');
                        append = SVNPathUtil.append(baseInfo.getURL().toString(), FileUtil.toSystemIndependentName(relativePath));
                    } else {
                        append = SVNPathUtil.append(baseInfo.getURL().toString(), systemIndependentPath);
                    }
                    pending.setURL(SVNURL.parseURIEncoded(append));
                }
                if (StatusType.STATUS_EXTERNAL.equals(pending.getNodeStatus())) {
                    externalsMap.put(pending.getFile(), pending.getInfo());
                }
                handler.consume(pending);
            } catch (SVNException e) {
                throw new SvnExceptionWrapper(e);
            }
        }

        @Override
        public void switchChangeList(String newList) {
            changelistName[0] = newList;
        }
    };
}
Also used : SVNException(org.tmatesoft.svn.core.SVNException) Info(org.jetbrains.idea.svn.info.Info) File(java.io.File)

Aggregations

SVNException (org.tmatesoft.svn.core.SVNException)95 File (java.io.File)37 SVNURL (org.tmatesoft.svn.core.SVNURL)37 VcsException (com.intellij.openapi.vcs.VcsException)18 SvnBindException (org.jetbrains.idea.svn.commandLine.SvnBindException)14 SVNConfigFile (org.tmatesoft.svn.core.internal.wc.SVNConfigFile)14 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 List (java.util.List)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 DefaultSVNOptions (org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions)7 SVNRepository (org.tmatesoft.svn.core.io.SVNRepository)7 SVNRevision (org.tmatesoft.svn.core.wc.SVNRevision)7 Date (java.util.Date)6 NotNull (org.jetbrains.annotations.NotNull)6 SVNCancelException (org.tmatesoft.svn.core.SVNCancelException)6 SVNLogEntry (org.tmatesoft.svn.core.SVNLogEntry)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5