Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/ftp/B6427768.java
41152 views
1
/*
2
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6427768
27
* @summary FtpURLConnection doesn't close FTP connection when login fails
28
* @modules java.base/sun.net.ftp
29
* @library ../www/ftptest/
30
* @build FtpServer FtpCommandHandler FtpAuthHandler FtpFileSystemHandler
31
* @run main/othervm/timeout=500 B6427768
32
*/
33
34
import java.net.*;
35
import java.io.*;
36
37
public class B6427768 {
38
// Need to test when login fails, so AuthHandler should always return
39
// false
40
static class MyAuthHandler implements FtpAuthHandler {
41
public int authType() {
42
return 2;
43
}
44
45
public boolean authenticate(String user, String password) {
46
return false;
47
}
48
49
public boolean authenticate(String user, String password, String account) {
50
return false;
51
}
52
}
53
54
static class MyFileSystemHandler implements FtpFileSystemHandler {
55
private String currentDir = "/";
56
57
public MyFileSystemHandler(String path) {
58
currentDir = path;
59
}
60
61
public boolean cd(String path) {
62
currentDir = path;
63
return true;
64
}
65
66
public boolean cdUp() {
67
return true;
68
}
69
70
public String pwd() {
71
return currentDir;
72
}
73
74
public InputStream getFile(String name) {
75
return null;
76
}
77
78
public long getFileSize(String name) {
79
return -1;
80
}
81
82
public boolean fileExists(String name) {
83
return false;
84
}
85
86
public InputStream listCurrentDir() {
87
return null;
88
}
89
90
public OutputStream putFile(String name) {
91
return null;
92
}
93
94
public boolean removeFile(String name) {
95
return false;
96
}
97
98
public boolean mkdir(String name) {
99
return false;
100
}
101
102
public boolean rename(String from, String to) {
103
return false;
104
}
105
}
106
107
public static void main(String[] args) throws IOException {
108
InetAddress loopback = InetAddress.getLoopbackAddress();
109
FtpServer server = new FtpServer(loopback, 0);
110
int port = server.getLocalPort();
111
server.setFileSystemHandler(new MyFileSystemHandler("/"));
112
server.setAuthHandler(new MyAuthHandler());
113
server.start();
114
URL url = new URL("ftp://user:passwd@" + server.getAuthority() + "/foo.txt");
115
URLConnection con = url.openConnection(Proxy.NO_PROXY);
116
// triggers the connection
117
try {
118
con.getInputStream();
119
} catch(sun.net.ftp.FtpLoginException e) {
120
// Give some time to the client thread to properly terminate.
121
try {
122
Thread.sleep(2000);
123
} catch (InterruptedException ie) {
124
// shouldn't happen
125
}
126
if (server.activeClientsCount() > 0) {
127
// If there are still active clients attached to the FTP
128
// server, it means we didn't quit properly
129
server.killClients();
130
throw new RuntimeException("URLConnection didn't close the ftp connection on failure to login");
131
}
132
} finally {
133
server.terminate();
134
}
135
}
136
}
137
138