nlight-jdev / jcouchdb

Automatically exported from code.google.com/p/jcouchdb
Other
0 stars 0 forks source link

Request to support Server.setCredentials method #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am using administration credentials on the svn version of couchdb

I would like to request a method stub such as 

public void setCredentials(String u, String p) throws CouchDBException;

in org.jcouchdb.db.Server

My implementation (really super basic cut and paste from apache HttpClient
website)

    public void setCredentials(String u, String p) throws CouchDBException{
        // copied from apache example
        // pass our credentials to HttpClient, they will only be used for
        // authenticating to servers with realm "realm" on the host
        // "www.verisign.com", to authenticate against
        // an arbitrary realm or host change the appropriate argument to null.
            httpClient.getState().setCredentials(

                    new AuthScope(hostConfiguration.getHost(),
hostConfiguration.getPort(), null),
                    new UsernamePasswordCredentials(u, p)
            );
    }

This passes the following really basic tests (it works with credentials to
create and delete databases, and it fails (throws exceptions) without
credentials when trying to create or delete databases.

    @Test(expected= CouchDBException.class) public void mustBeAdmin() { 
        Server server = new org.jcouchdb.db.ServerImpl(COUCHDB_HOST,
COUCHDB_PORT);
        List<String> databases = server.listDatabases();
        log.warn("visible databases = " + databases);
        if (databases.contains(TESTDB_NAME))
        {
            // expect a failure without login
            server.deleteDatabase(TESTDB_NAME);
        }else{
            // expect a failure without login
            server.createDatabase(TESTDB_NAME);
        }
    }

    @Test public void simpleAddDBDeleteDB() {
        Server server = new org.jcouchdb.db.ServerImpl(COUCHDB_HOST,
COUCHDB_PORT);
        server.setCredentials("admin","secretepassword");
        List<String> databases = server.listDatabases();
        if (databases.contains(TESTDB_NAME))
        {
            server.deleteDatabase(TESTDB_NAME);
            databases = server.listDatabases();
            assertFalse(databases.contains(TESTDB_NAME));
        }
        server.createDatabase(TESTDB_NAME);
        databases = server.listDatabases();
        assertTrue(databases.contains(TESTDB_NAME));
        server.deleteDatabase(TESTDB_NAME);
        databases = server.listDatabases();
        assertFalse(databases.contains(TESTDB_NAME));
    }

Original issue reported on code.google.com by jma...@translab.its.uci.edu on 22 Dec 2008 at 7:37

GoogleCodeExporter commented 8 years ago
is the current implementation state enough?

Original comment by ff...@gmx.de on 19 Apr 2009 at 5:36

GoogleCodeExporter commented 8 years ago
Yes as a matter of fact I just upgraded jcouchdb last week and noticed (and 
used) the
new implementation.  It works fine for me with the released version of couchdb.

Original comment by jma...@translab.its.uci.edu on 20 Apr 2009 at 3:29

GoogleCodeExporter commented 8 years ago
closing this now.

Original comment by ff...@gmx.de on 20 Apr 2009 at 3:54