Skip to content

Commit 913f15d

Browse files
author
diego Dupin
committed
[misc] test PAM with maxscale
1 parent 320d699 commit 913f15d

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/test/java/org/mariadb/jdbc/integration/Common.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class Common {
3232
public static int port;
3333
public static String user;
3434
public static String password;
35+
public static String database;
36+
public static String defaultOther;
3537
public static TcpProxy proxy;
3638
public static String mDefUrl;
3739
private static Instant initialTest;
@@ -41,7 +43,6 @@ public class Common {
4143
Common.class.getClassLoader().getResourceAsStream("conf.properties")) {
4244
Properties prop = new Properties();
4345
prop.load(inputStream);
44-
String defaultOther;
4546
String val = System.getenv("TEST_REQUIRE_TLS");
4647
if ("1".equals(val)) {
4748
String cert = System.getenv("TEST_DB_SERVER_CERT");
@@ -53,10 +54,11 @@ public class Common {
5354
user = get("DB_USER", prop);
5455
port = Integer.parseInt(get("DB_PORT", prop));
5556
password = get("DB_PASSWORD", prop);
57+
database = get("DB_DATABASE", prop);
5658
mDefUrl =
5759
String.format(
5860
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&restrictedAuth=none&%s",
59-
hostname, port, get("DB_DATABASE", prop), user, password, defaultOther);
61+
hostname, port, database, user, password, defaultOther);
6062

6163
} catch (IOException io) {
6264
io.printStackTrace();

src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ public void various() throws SQLException {
762762
assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, sharedConn.getHoldability());
763763
sharedConn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
764764
assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, sharedConn.getHoldability());
765-
assertNotEquals(0, sharedConn.getWaitTimeout());
766765
}
767766

768767
@Test
@@ -814,7 +813,6 @@ public void pamAuthPlugin() throws Throwable {
814813
Assumptions.assumeTrue(
815814
isMariaDBServer()
816815
&& System.getenv("TEST_PAM_USER") != null
817-
&& !"maxscale".equals(System.getenv("srv"))
818816
&& !"skysql".equals(System.getenv("srv"))
819817
&& !"skysql-ha".equals(System.getenv("srv")));
820818

@@ -824,21 +822,40 @@ public void pamAuthPlugin() throws Throwable {
824822
} catch (SQLException sqle) {
825823
// might be already set
826824
}
827-
stmt.execute("DROP USER IF EXISTS 'testPam'@'%'");
828-
stmt.execute("CREATE USER 'testPam'@'%' IDENTIFIED VIA pam USING 'mariadb'");
829-
stmt.execute("GRANT SELECT ON *.* TO 'testPam'@'%' IDENTIFIED VIA pam");
825+
826+
String pamUser = System.getenv("TEST_PAM_USER");
827+
String pamPwd = System.getenv("TEST_PAM_PWD");
828+
829+
stmt.execute("DROP USER IF EXISTS '" + pamUser + "'@'%'");
830+
stmt.execute("CREATE USER '" + pamUser + "'@'%' IDENTIFIED VIA pam USING 'mariadb'");
831+
stmt.execute("GRANT SELECT ON *.* TO '" + pamUser + "'@'%' IDENTIFIED VIA pam");
830832
stmt.execute("FLUSH PRIVILEGES");
831833

832-
try (Connection connection = createCon("user=testPam&password=myPwd&restrictedAuth=dialog")) {
833-
// must have succeeded
834-
connection.getCatalog();
834+
int testPort = this.port;
835+
if (System.getenv("TEST_PAM_PORT") != null) {
836+
testPort = Integer.parseInt(System.getenv("TEST_PAM_PORT"));
837+
}
838+
String connStr =
839+
String.format(
840+
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&%s",
841+
hostname, testPort, database, pamUser, pamPwd, defaultOther);
842+
try {
843+
try (Connection connection =
844+
DriverManager.getConnection(connStr + "&restrictedAuth=dialog")) {
845+
// must have succeeded
846+
connection.getCatalog();
847+
}
848+
} catch (SQLException e) {
849+
System.err.println("fail with connectionString : " + connStr + "&restrictedAuth=dialog");
850+
throw e;
835851
}
852+
836853
Common.assertThrowsContains(
837854
SQLException.class,
838-
() -> createCon("user=testPam&password=myPwd&restrictedAuth=other"),
855+
() -> DriverManager.getConnection(connStr + "&restrictedAuth=other"),
839856
"Client restrict authentication plugin to a limited set of authentication");
840857

841-
stmt.execute("drop user testPam@'%'");
858+
stmt.execute("drop user " + pamUser + "@'%'");
842859
}
843860

844861
@Nested
@@ -943,7 +960,7 @@ public void localSocket() throws Exception {
943960
String.format(
944961
"jdbc:mariadb:///%s?user=testSocket&password=heyPassw!µ20§rd&localSocket=%s&tcpAbortiveClose&tcpKeepAlive",
945962
sharedConn.getCatalog(), path);
946-
System.out.println(url);
963+
947964
try (java.sql.Connection connection = DriverManager.getConnection(url)) {
948965
connection.setNetworkTimeout(null, 300);
949966
rs = connection.createStatement().executeQuery("select 1");

0 commit comments

Comments
 (0)