Github user srowen commented on a diff in the pull request: https://github.com/apache/spark/pull/10452#discussion_r48405431 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala --- @@ -517,4 +519,65 @@ class JDBCSuite extends SparkFunSuite assert(rows(0).getAs[java.sql.Timestamp](2) === java.sql.Timestamp.valueOf("2002-02-20 11:22:33.543543")) } + + test("test masking of credentials in the properties") { + val df = sql("SELECT * FROM parts") + // make sure plan credentials are not leaked any where in the plan. + val explain = ExplainCommand(df.queryExecution.logical, extended = true) + sqlContext.executePlan(explain).executedPlan.executeCollect().foreach { + r => assert(!List("testPass", "testUser").exists(r.toString.contains)) + } + // test the JdbcRelation toString method credentials masking format + val jdbcRelationStr = s"""JDBCRelation(jdbc:h2:...,TEST.PEOPLE, + |Partition[3](JDBCPartition(THEID < 2,0)..., + |JDBCPartition(THEID >= 3,2)), + |Map(url -> jdbc:h2:..., upperbound -> 4, + | lowerbound -> 1, numpartitions -> 3, + | dbtable -> TEST.PEOPLE, partitioncolumn -> THEID, + | user -> ***, password -> ***)) + |""".stripMargin.replaceAll("\n", "") + df.queryExecution.analyzed.collect { + case r: LogicalRelation => assert(r.relation.toString == jdbcRelationStr) + } + } + + test("test masking of credentials in the connection url") { + val df = sqlContext.read.jdbc(urlWithUserAndPass, "TEST.PEOPLE", new Properties) + // test to make sure credentials are not leaking into the plan strings. + val explain = ExplainCommand(df.queryExecution.logical, extended = true) + sqlContext.executePlan(explain).executedPlan.executeCollect().foreach { + r => assert(!List("testPass", "testUser").exists(r.toString.contains)) + } + + // test the JdbcRelation toString method credentials masking format + val jdbcRelationStr = s"""JDBCRelation(jdbc:h2:mem:testdb0;user=***;password=***, + |TEST.PEOPLE,Partition[1](JDBCPartition(null,0)),Map()) + |""".stripMargin.replaceAll("\n", "") + df.queryExecution.analyzed.collect { + case r: LogicalRelation => assert(r.relation.toString == jdbcRelationStr) + } + } + + test("test masking of credentials in different database dialects") { + List( + ("jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true", + "jdbc:postgresql://localhost/test?user=***&password=***&ssl=true"), + ("jdbc:mysql://localhost/test?user=minty&password=greatsqldb", + "jdbc:mysql://localhost/test?user=***&password=***"), + ("jdbc:sqlserver://host:port;databasename=name;user=yourUser;password=yourPwd", + "jdbc:sqlserver://host:port;databasename=name;user=***;password=***"), + ("jdbc:db2://host:port/dbName:user=yourUser;password=yourPwd;", + "jdbc:db2://host:port/dbName:user=***;password=***;"), + ("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl", + "jdbc:oracle:thin:***/***@myhost:1521:orcl"), + ("jdbc:oracle:oci8:scott/tiger@myhost", + "jdbc:oracle:oci8:***/***@myhost"), + ("jdbc:teradata://localhost/DATABASE=dbName,user=yourUser,password=yourPwd", + "jdbc:teradata://localhost/DATABASE=dbName,user=***,password=***"), + ("jdbc:newdb://localhost/DATABASE=dbName,user=yourUser,pwd=yourPwd", + "jdbc:newdb:...") + ).map(urldata => { --- End diff -- foreach with a case expression to make this clearer?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org