Search in sources :

Example 21 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 22 with SVNException

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

the class SvnAuthenticationTest method testPlaintextPromptAndSecondPrompt.

public void testPlaintextPromptAndSecondPrompt() 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(false);
    final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");
    final SVNURL url2 = SVNURL.parseURIEncoded("http://some.other.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);
            long start = System.currentTimeMillis();
            waitListenerStep(start, listener, 3);
            Assert.assertEquals(1, myTestInteraction.getNumPlaintextPrompt());
            // actually password not saved, but save was called
            savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);
            savedOnceListener.reset();
            myTestInteraction.reset();
            listener.addStep(new Trinity<>(ProviderType.persistent, url2, Type.request));
            listener.addStep(new Trinity<>(ProviderType.interactive, url2, Type.request));
            listener.addStep(new Trinity<>(ProviderType.persistent, url2, Type.without_pasword_save));
            commonScheme(url2, false, "anotherRealm");
            start = System.currentTimeMillis();
            waitListenerStep(start, listener, 6);
            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(6, listener.getCnt());
    listener.assertForAwt();
    savedOnceListener.assertForAwt();
    // didn't called to save for 2nd time
    savedOnceListener.assertNotSaved(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)

Example 23 with SVNException

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

the class SvnAuthenticationTest method testWhenPassSaveNoForGroup.

public void testWhenPassSaveNoForGroup() 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 String contents = FileUtil.loadFile(servers);
    final String groups = "[groups]";
    final int idx = contents.indexOf(groups);
    Assert.assertTrue(idx != -1);
    final String newContents = contents.substring(0, idx + groups.length()) + "\nsomegroup=some*\n" + contents.substring(idx + groups.length()) + "\n[somegroup]\nstore-passwords=no\n";
    final File oldServers = new File(myConfiguration.getConfigurationDirectory(), "config_old");
    FileUtil.rename(servers, oldServers);
    try {
        servers.createNewFile();
        FileUtil.appendToFile(servers, 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(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 24 with SVNException

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

the class SvnBusyOnAddTest method getStatus.

@Nullable
private String getStatus(final File ioFile) throws SVNException {
    try {
        SVNStatusClient readClient = new SVNStatusClient((ISVNRepositoryPool) null, new DefaultSVNOptions());
        final SVNStatus status = readClient.doStatus(ioFile, false);
        return status == null ? null : status.getNodeStatus().toString();
    } catch (SVNException e) {
        if (SVNErrorCode.WC_NOT_WORKING_COPY.equals(e.getErrorMessage().getErrorCode())) {
            return null;
        }
        throw e;
    }
}
Also used : DefaultSVNOptions(org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions) SVNException(org.tmatesoft.svn.core.SVNException) Nullable(org.jetbrains.annotations.Nullable)

Example 25 with SVNException

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

the class SvnBusyOnAddTest method testStatusDoesNotLockForWrite.

public void testStatusDoesNotLockForWrite() throws Exception {
    final File ioFile = new File(myWorkingCopyRoot, filename);
    ioFile.getParentFile().mkdirs();
    /*SVNWCClient client11 = new SVNWCClient((ISVNRepositoryPool)null, new DefaultSVNOptions());
    client11.doAdd(ioFile.getParentFile(), true, false, true, true);*/
    ioFile.createNewFile();
    try {
        final SVNStatusClient readClient = new SVNStatusClient((ISVNRepositoryPool) null, new DefaultSVNOptions());
        final Semaphore semaphore = new Semaphore();
        final Semaphore semaphoreMain = new Semaphore();
        final Semaphore semaphoreWokeUp = new Semaphore();
        final AtomicReference<Boolean> wasUp = new AtomicReference<>(false);
        final ISVNStatusHandler handler = status -> {
            semaphore.waitFor();
            wasUp.set(true);
        };
        semaphore.down();
        semaphoreMain.down();
        semaphoreWokeUp.down();
        final SVNException[] exception = new SVNException[1];
        Thread thread = new Thread(() -> {
            try {
                semaphoreMain.up();
                readClient.doStatus(myWorkingCopyRoot, true, false, true, false, handler);
                semaphoreWokeUp.up();
            } catch (SVNException e) {
                exception[0] = e;
            }
        }, "svn test");
        thread.start();
        semaphoreMain.waitFor();
        TimeoutUtil.sleep(5);
        SVNWCClient client = new SVNWCClient((ISVNRepositoryPool) null, new DefaultSVNOptions());
        client.doAdd(ioFile.getParentFile(), true, false, true, true);
        semaphore.up();
        semaphoreWokeUp.waitFor();
        Assert.assertEquals(true, wasUp.get().booleanValue());
        if (exception[0] != null) {
            throw exception[0];
        }
        thread.join();
    } finally {
        ioFile.delete();
    }
}
Also used : SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) PluginPathManager(com.intellij.openapi.application.PluginPathManager) SVNException(org.tmatesoft.svn.core.SVNException) PathManager(com.intellij.openapi.application.PathManager) Test(org.junit.Test) SVNErrorCode(org.tmatesoft.svn.core.SVNErrorCode) ISVNWCDb(org.tmatesoft.svn.core.internal.wc17.db.ISVNWCDb) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File) SVNWCContext(org.tmatesoft.svn.core.internal.wc17.SVNWCContext) org.tmatesoft.svn.core.wc(org.tmatesoft.svn.core.wc) Nullable(org.jetbrains.annotations.Nullable) Assert(junit.framework.Assert) TimeoutUtil(com.intellij.util.TimeoutUtil) Semaphore(com.intellij.util.concurrency.Semaphore) TestCase(junit.framework.TestCase) DefaultSVNOptions(org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions) SVNWCDb(org.tmatesoft.svn.core.internal.wc17.db.SVNWCDb) Before(org.junit.Before) DefaultSVNOptions(org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(com.intellij.util.concurrency.Semaphore) SVNException(org.tmatesoft.svn.core.SVNException) 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