From: Christian Ullrich <chris@chrullrich.net>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Cc: Craig Ringer <craig@2ndquadrant.com>
Subject: Re: Support waffle>1.7.4
Date: Tue, 10 May 2016 01:49:21 +0200
Message-ID: <f52e2052-0c2e-7ed4-6185-de4e02b444d4@chrullrich.net> (raw)
In-Reply-To: <5fb97533-b4c9-86c6-7ec2-d782b2155ac6@chrullrich.net>
References: <nejcjl$19e$1@ger.gmane.org>
<CAMsr+YE_oSxLiLWof0jXAtCrtbQOvAY1cFfGgQjrfHA2vGEKsQ@mail.gmail.com>
<5713EF2E.7040206@chrullrich.net>
<5fb97533-b4c9-86c6-7ec2-d782b2155ac6@chrullrich.net>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
* Christian Ullrich wrote:
> I thought about writing a few [SSPI tests], and I may yet get around
> to that,
Attached is a proposed patch; I cannot send it as a PR because it is
dependent on Pavel Raiskup's as yet unmerged #546. The Waffle-free build
option is clearly coming, and there is little point in having SSPI tests
that then cannot be turned off.
Some explanations:
- Both successful and unsuccessful authentication is tested, the latter
to ensure that a configuration mistake (such as a "trust" line left
in pg_hba.conf) has not caused *both* tests to succeed when they
should have failed.
- Setting up to run these tests is not entirely (or at all) trivial; it
requires running the database server as an account that is capable of
SSPI authentication (such as a virtual service account, e.g.
"NT SERVICE\PostgreSQL") on both domain member and non-member
systems, or a domain user account.
- Additionally, both pg_hba.conf and, in most cases, pg_ident.conf must
be configured. In particular, the user account that runs the tests
must be permitted to authenticate as the database role configured in
build.properties.
- The tests are not run when Waffle is disabled. I would have preferred
to have a separate option to turn them off even when building with
Waffle because the setup is so difficult. I could not think of a way
to make Maven do this, mostly because profiles cannot be chained, and
profile activation cannot use two variables, for example
(!enableWaffle || disableSSPITests).
- There is an intermittent problem where testUnauthorized() fails
because it gets the wrong exception: It expects SQLSTATE 28000 from
the server, but sometimes it gets 08001 generated internally in the
driver. No idea what causes that. I did not want to blindly accept any
error as proof of failed authentication.
--
Christian
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbcAttachments:sspi-test.patch (text/plain, 5.5K) downloaddiff --git a/build.properties b/build.propertiesindex e23f96a..14c0e9e 100644--- a/build.properties+++ b/build.properties@@ -9,6 +9,7 @@ username=test
password=test
privilegedUser=postgres
privilegedPassword=
+sspiusername=testsspi
preparethreshold=5
loglevel=0
protocolVersion=0
diff --git a/pgjdbc/pom.xml b/pgjdbc/pom.xmlindex dab5308..2e5ab56 100644--- a/pgjdbc/pom.xml+++ b/pgjdbc/pom.xml@@ -133,6 +133,9 @@
<exclude>org/postgresql/sspi/NTDSAPIWrapper.java</exclude>
<exclude>org/postgresql/sspi/SSPIClient.java</exclude>
</excludes>
+ <testExcludes>+ <exclude>org/postgresql/test/sspi/*.java</exclude>+ </testExcludes>
</configuration>
</plugin>
</plugins>
diff --git a/pgjdbc/src/main/java/org/postgresql/util/PSQLState.java b/pgjdbc/src/main/java/org/postgresql/util/PSQLState.javaindex 21bfc82..3b40229 100644--- a/pgjdbc/src/main/java/org/postgresql/util/PSQLState.java+++ b/pgjdbc/src/main/java/org/postgresql/util/PSQLState.java@@ -91,6 +91,7 @@ public class PSQLState implements java.io.Serializable {
public final static PSQLState TRANSACTION_STATE_INVALID = new PSQLState("25000");
public final static PSQLState ACTIVE_SQL_TRANSACTION = new PSQLState("25001");
public final static PSQLState NO_ACTIVE_SQL_TRANSACTION = new PSQLState("25P01");
+ public final static PSQLState INVALID_AUTHORIZATION_SPECIFICATION = new PSQLState("28000");
public final static PSQLState STATEMENT_NOT_ALLOWED_IN_FUNCTION_CALL = new PSQLState("2F003");
diff --git a/pgjdbc/src/test/java/org/postgresql/test/TestUtil.java b/pgjdbc/src/test/java/org/postgresql/test/TestUtil.javaindex 2e12cc8..417be9c 100644--- a/pgjdbc/src/test/java/org/postgresql/test/TestUtil.java+++ b/pgjdbc/src/test/java/org/postgresql/test/TestUtil.java@@ -121,6 +121,13 @@ public class TestUtil {
}
/*
+ * Returns the user for SSPI authentication tests+ */+ public static String getSSPIUser() {+ return System.getProperty("sspiusername");+ }++ /*
* postgres like user
*/
public static String getPrivilegedUser() {
@@ -266,7 +273,11 @@ public class TestUtil {
public static java.sql.Connection openDB(Properties props) throws Exception {
initDriver();
- String user = getUser();+ // Allow properties to override the user name.+ String user = props.getProperty("username");+ if (user == null) {+ user = getUser();+ }
if (user == null) {
throw new IllegalArgumentException(
"user name is not specified. Please specify 'username' property via -D or build.properties");
diff --git a/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITest.java b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITest.javanew file mode 100644index 0000000..9940fe2--- /dev/null+++ b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITest.java@@ -0,0 +1,53 @@+package org.postgresql.test.sspi;++import org.postgresql.test.TestUtil;+import org.postgresql.util.PSQLException;+import org.postgresql.util.PSQLState;++import junit.framework.TestCase;++import java.sql.Connection;+import java.sql.Statement;+import java.util.Properties;++/*+ * These tests require a working SSPI authentication setup+ * in the database server that allows the executing user+ * to authenticate as the "sspiusername" in the build+ * configuration.+ */+public class SSPITest extends TestCase {++ /*+ * Tests that SSPI login succeeds and a query can be run.+ */+ public void testAuthorized() throws Exception {+ Properties props = new Properties();+ props.setProperty("username", TestUtil.getSSPIUser());+ Connection con = TestUtil.openDB(props);++ Statement stmt = con.createStatement();+ stmt.executeQuery("SELECT 1");++ TestUtil.closeDB(con);+ }++ /*+ * Tests that SSPI login fails with an unknown/unauthorized+ * user name.+ */+ public void testUnauthorized() throws Exception {+ Properties props = new Properties();+ props.setProperty("username", "invalid" + TestUtil.getSSPIUser());++ try {+ Connection con = TestUtil.openDB(props);+ TestUtil.closeDB(con);+ fail("Expected a PSQLException");+ } catch (PSQLException e) {+ assertEquals(PSQLState.INVALID_AUTHORIZATION_SPECIFICATION.getState(), e.getSQLState());+ }+ }++}+diff --git a/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITestSuite.java b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITestSuite.javanew file mode 100644index 0000000..6f4c706--- /dev/null+++ b/pgjdbc/src/test/java/org/postgresql/test/sspi/SSPITestSuite.java@@ -0,0 +1,33 @@+/*-------------------------------------------------------------------------+*+* Copyright (c) 2004-2014, PostgreSQL Global Development Group+*+*+*-------------------------------------------------------------------------+*/++package org.postgresql.test.sspi;++import junit.framework.JUnit4TestAdapter;+import junit.framework.TestSuite;++/*+ * Executes all known tests for SSPI and includes some utility methods.+ */+public class SSPITestSuite extends TestSuite {++ /*+ * The main entry point for JUnit+ */+ public static TestSuite suite() throws Exception {+ TestSuite suite = new TestSuite();++ //+ // Add one line per class in our test cases. These should be in order of+ // complexity.+ suite.addTestSuite(SSPITest.class);++ // That's all folks+ return suite;+ }+}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: chris@chrullrich.net, craig@2ndquadrant.com
Subject: Re: Support waffle>1.7.4
In-Reply-To: <f52e2052-0c2e-7ed4-6185-de4e02b444d4@chrullrich.net>
References: <nejcjl$19e$1@ger.gmane.org> <CAMsr+YE_oSxLiLWof0jXAtCrtbQOvAY1cFfGgQjrfHA2vGEKsQ@mail.gmail.com> <5713EF2E.7040206@chrullrich.net> <5fb97533-b4c9-86c6-7ec2-d782b2155ac6@chrullrich.net> <f52e2052-0c2e-7ed4-6185-de4e02b444d4@chrullrich.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox