|
1 | 1 | /* |
2 | | - Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 |
|
4 | 4 | The MySQL Connector/J is licensed under the terms of the GPLv2 |
5 | 5 | <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors. |
@@ -733,6 +733,7 @@ public void testLocalInfileWithUrl() throws Exception { |
733 | 733 | createTable("testLocalInfileWithUrl", "(field1 LONGTEXT)"); |
734 | 734 |
|
735 | 735 | Properties props = new Properties(); |
| 736 | + props.setProperty("allowLoadLocalInfile", "true"); |
736 | 737 | props.setProperty("allowUrlInLocalInfile", "true"); |
737 | 738 |
|
738 | 739 | Connection loadConn = getConnectionWithProps(props); |
@@ -784,25 +785,40 @@ public void testLocalInfileWithUrl() throws Exception { |
784 | 785 | public void testLocalInfileDisabled() throws Exception { |
785 | 786 | createTable("testLocalInfileDisabled", "(field1 varchar(255))"); |
786 | 787 |
|
787 | | - File infile = File.createTempFile("foo", "txt"); |
| 788 | + final File infile = File.createTempFile("foo", "txt"); |
788 | 789 | infile.deleteOnExit(); |
789 | 790 | //String url = infile.toURL().toExternalForm(); |
790 | 791 | FileWriter output = new FileWriter(infile); |
791 | 792 | output.write("Test"); |
792 | 793 | output.flush(); |
793 | 794 | output.close(); |
794 | 795 |
|
795 | | - Connection loadConn = getConnectionWithProps(new Properties()); |
| 796 | + // Test load local infile support disabled via client capabilities by default. |
| 797 | + assertThrows(SQLException.class, |
| 798 | + versionMeetsMinimum(8, 0, 19) ? "Loading local data is disabled;.*" : "The used command is not allowed with this MySQL version", |
| 799 | + new Callable<Void>() { |
| 800 | + public Void call() throws Exception { |
| 801 | + ConnectionTest.this.stmt.executeUpdate("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled"); |
| 802 | + return null; |
| 803 | + } |
| 804 | + }); |
| 805 | + |
| 806 | + // Test load local infile support enabled via client capabilities but disabled on the connector. |
| 807 | + Properties props = new Properties(); |
| 808 | + props.setProperty("allowLoadLocalInfile", "true"); |
| 809 | + final Connection loadConn = getConnectionWithProps(props); |
796 | 810 |
|
797 | 811 | try { |
798 | | - // have to do this after connect, otherwise it's the server that's enforcing it |
799 | | - ((com.mysql.jdbc.Connection) loadConn).setAllowLoadLocalInfile(false); |
800 | | - try { |
801 | | - loadConn.createStatement().execute("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled"); |
802 | | - fail("Should've thrown an exception."); |
803 | | - } catch (SQLException sqlEx) { |
804 | | - assertEquals(SQLError.SQL_STATE_GENERAL_ERROR, sqlEx.getSQLState()); |
805 | | - } |
| 812 | + // Must be set after connect, otherwise it's the server that's enforcing it. |
| 813 | + ((ConnectionProperties) loadConn).setAllowLoadLocalInfile(false); |
| 814 | + |
| 815 | + assertThrows(SQLException.class, "Server asked for stream in response to LOAD DATA LOCAL INFILE but functionality is disabled at client by " |
| 816 | + + "'allowLoadLocalInfile' being set to 'false'\\.", new Callable<Void>() { |
| 817 | + public Void call() throws Exception { |
| 818 | + loadConn.createStatement().execute("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled"); |
| 819 | + return null; |
| 820 | + } |
| 821 | + }); |
806 | 822 |
|
807 | 823 | assertFalse(loadConn.createStatement().executeQuery("SELECT * FROM testLocalInfileDisabled").next()); |
808 | 824 | } finally { |
|
0 commit comments