Asankhaya Sharma
commited on
Commit
·
f7b4e15
1
Parent(s):
63d6bd1
test dataset viewer
Browse files
data/test/AbstractDiskHttpDataTest.java
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Copyright 2020 The Netty Project
|
3 |
+
*
|
4 |
+
* The Netty Project licenses this file to you under the Apache License,
|
5 |
+
* version 2.0 (the "License"); you may not use this file except in compliance
|
6 |
+
* with the License. You may obtain a copy of the License at:
|
7 |
+
*
|
8 |
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
*
|
10 |
+
* Unless required by applicable law or agreed to in writing, software
|
11 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13 |
+
* License for the specific language governing permissions and limitations
|
14 |
+
* under the License.
|
15 |
+
*/
|
16 |
+
package io.netty.handler.codec.http.multipart;
|
17 |
+
|
18 |
+
import io.netty.buffer.ByteBuf;
|
19 |
+
import io.netty.buffer.ByteBufUtil;
|
20 |
+
import io.netty.util.internal.PlatformDependent;
|
21 |
+
import org.junit.Test;
|
22 |
+
|
23 |
+
import java.io.File;
|
24 |
+
import java.io.FileOutputStream;
|
25 |
+
import java.nio.charset.Charset;
|
26 |
+
import java.util.Arrays;
|
27 |
+
import java.util.UUID;
|
28 |
+
|
29 |
+
import static io.netty.util.CharsetUtil.UTF_8;
|
30 |
+
import static org.junit.Assert.assertEquals;
|
31 |
+
import static org.junit.Assert.assertFalse;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* {@link AbstractDiskHttpData} test cases
|
35 |
+
*/
|
36 |
+
public class AbstractDiskHttpDataTest {
|
37 |
+
|
38 |
+
@Test
|
39 |
+
public void testGetChunk() throws Exception {
|
40 |
+
TestHttpData test = new TestHttpData("test", UTF_8, 0);
|
41 |
+
try {
|
42 |
+
// BUG: CWE-378 Creation of Temporary File With Insecure Permissions
|
43 |
+
// File tmpFile = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
|
44 |
+
// FIXED:
|
45 |
+
File tmpFile = PlatformDependent.createTempFile(UUID.randomUUID().toString(), ".tmp", null);
|
46 |
+
tmpFile.deleteOnExit();
|
47 |
+
FileOutputStream fos = new FileOutputStream(tmpFile);
|
48 |
+
byte[] bytes = new byte[4096];
|
49 |
+
PlatformDependent.threadLocalRandom().nextBytes(bytes);
|
50 |
+
try {
|
51 |
+
fos.write(bytes);
|
52 |
+
fos.flush();
|
53 |
+
} finally {
|
54 |
+
fos.close();
|
55 |
+
}
|
56 |
+
test.setContent(tmpFile);
|
57 |
+
ByteBuf buf1 = test.getChunk(1024);
|
58 |
+
assertEquals(buf1.readerIndex(), 0);
|
59 |
+
assertEquals(buf1.writerIndex(), 1024);
|
60 |
+
ByteBuf buf2 = test.getChunk(1024);
|
61 |
+
assertEquals(buf2.readerIndex(), 0);
|
62 |
+
assertEquals(buf2.writerIndex(), 1024);
|
63 |
+
assertFalse("Arrays should not be equal",
|
64 |
+
Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)));
|
65 |
+
} finally {
|
66 |
+
test.delete();
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
private static final class TestHttpData extends AbstractDiskHttpData {
|
71 |
+
|
72 |
+
private TestHttpData(String name, Charset charset, long size) {
|
73 |
+
super(name, charset, size);
|
74 |
+
}
|
75 |
+
|
76 |
+
@Override
|
77 |
+
protected String getDiskFilename() {
|
78 |
+
return null;
|
79 |
+
}
|
80 |
+
|
81 |
+
@Override
|
82 |
+
protected String getPrefix() {
|
83 |
+
return null;
|
84 |
+
}
|
85 |
+
|
86 |
+
@Override
|
87 |
+
protected String getBaseDirectory() {
|
88 |
+
return null;
|
89 |
+
}
|
90 |
+
|
91 |
+
@Override
|
92 |
+
protected String getPostfix() {
|
93 |
+
return null;
|
94 |
+
}
|
95 |
+
|
96 |
+
@Override
|
97 |
+
protected boolean deleteOnExit() {
|
98 |
+
return false;
|
99 |
+
}
|
100 |
+
|
101 |
+
@Override
|
102 |
+
public HttpData copy() {
|
103 |
+
return null;
|
104 |
+
}
|
105 |
+
|
106 |
+
@Override
|
107 |
+
public HttpData duplicate() {
|
108 |
+
return null;
|
109 |
+
}
|
110 |
+
|
111 |
+
@Override
|
112 |
+
public HttpData retainedDuplicate() {
|
113 |
+
return null;
|
114 |
+
}
|
115 |
+
|
116 |
+
@Override
|
117 |
+
public HttpData replace(ByteBuf content) {
|
118 |
+
return null;
|
119 |
+
}
|
120 |
+
|
121 |
+
@Override
|
122 |
+
public HttpDataType getHttpDataType() {
|
123 |
+
return null;
|
124 |
+
}
|
125 |
+
|
126 |
+
@Override
|
127 |
+
public int compareTo(InterfaceHttpData o) {
|
128 |
+
return 0;
|
129 |
+
}
|
130 |
+
}
|
131 |
+
}
|
data/train/AbstractConstantRestrictor.java
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
package org.jolokia.restrictor;
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Copyright 2009-2011 Roland Huss
|
5 |
+
*
|
6 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7 |
+
* you may not use this file except in compliance with the License.
|
8 |
+
* You may obtain a copy of the License at
|
9 |
+
*
|
10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11 |
+
*
|
12 |
+
* Unless required by applicable law or agreed to in writing, software
|
13 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15 |
+
* See the License for the specific language governing permissions and
|
16 |
+
* limitations under the License.
|
17 |
+
*/
|
18 |
+
|
19 |
+
import javax.management.ObjectName;
|
20 |
+
|
21 |
+
import org.jolokia.util.HttpMethod;
|
22 |
+
import org.jolokia.util.RequestType;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Base restrictor which alway returns the constant given
|
26 |
+
* at construction time
|
27 |
+
*
|
28 |
+
* @author roland
|
29 |
+
* @since 06.10.11
|
30 |
+
*/
|
31 |
+
public abstract class AbstractConstantRestrictor implements Restrictor {
|
32 |
+
|
33 |
+
private boolean isAllowed;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Create restrictor which always returns the given value on every check
|
37 |
+
* method.
|
38 |
+
*
|
39 |
+
* @param pAllowed whether access is allowed or denied
|
40 |
+
*/
|
41 |
+
protected AbstractConstantRestrictor(boolean pAllowed) {
|
42 |
+
isAllowed = pAllowed;
|
43 |
+
}
|
44 |
+
|
45 |
+
/** {@inheritDoc} */
|
46 |
+
public final boolean isHttpMethodAllowed(HttpMethod pMethod) {
|
47 |
+
return isAllowed;
|
48 |
+
}
|
49 |
+
|
50 |
+
/** {@inheritDoc} */
|
51 |
+
public final boolean isTypeAllowed(RequestType pType) {
|
52 |
+
return isAllowed;
|
53 |
+
}
|
54 |
+
|
55 |
+
/** {@inheritDoc} */
|
56 |
+
public final boolean isAttributeReadAllowed(ObjectName pName, String pAttribute) {
|
57 |
+
return isAllowed;
|
58 |
+
}
|
59 |
+
|
60 |
+
/** {@inheritDoc} */
|
61 |
+
public final boolean isAttributeWriteAllowed(ObjectName pName, String pAttribute) {
|
62 |
+
return isAllowed;
|
63 |
+
}
|
64 |
+
|
65 |
+
/** {@inheritDoc} */
|
66 |
+
public final boolean isOperationAllowed(ObjectName pName, String pOperation) {
|
67 |
+
return isAllowed;
|
68 |
+
}
|
69 |
+
|
70 |
+
/** {@inheritDoc} */
|
71 |
+
public final boolean isRemoteAccessAllowed(String... pHostOrAddress) {
|
72 |
+
return isAllowed;
|
73 |
+
}
|
74 |
+
|
75 |
+
/** {@inheritDoc} */
|
76 |
+
// BUG: CWE-352 Cross-Site Request Forgery (CSRF)
|
77 |
+
// public boolean isCorsAccessAllowed(String pOrigin) {
|
78 |
+
// FIXED:
|
79 |
+
public boolean isOriginAllowed(String pOrigin, boolean pIsStrictCheck) {
|
80 |
+
return isAllowed;
|
81 |
+
}
|
82 |
+
}
|
data/valid/AbstractDiskHttpDataTest.java
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Copyright 2020 The Netty Project
|
3 |
+
*
|
4 |
+
* The Netty Project licenses this file to you under the Apache License,
|
5 |
+
* version 2.0 (the "License"); you may not use this file except in compliance
|
6 |
+
* with the License. You may obtain a copy of the License at:
|
7 |
+
*
|
8 |
+
* https://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
*
|
10 |
+
* Unless required by applicable law or agreed to in writing, software
|
11 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13 |
+
* License for the specific language governing permissions and limitations
|
14 |
+
* under the License.
|
15 |
+
*/
|
16 |
+
package io.netty.handler.codec.http.multipart;
|
17 |
+
|
18 |
+
import io.netty.buffer.ByteBuf;
|
19 |
+
import io.netty.buffer.ByteBufUtil;
|
20 |
+
import io.netty.util.internal.PlatformDependent;
|
21 |
+
import org.junit.Test;
|
22 |
+
|
23 |
+
import java.io.File;
|
24 |
+
import java.io.FileOutputStream;
|
25 |
+
import java.nio.charset.Charset;
|
26 |
+
import java.util.Arrays;
|
27 |
+
import java.util.UUID;
|
28 |
+
|
29 |
+
import static io.netty.util.CharsetUtil.UTF_8;
|
30 |
+
import static org.junit.Assert.assertEquals;
|
31 |
+
import static org.junit.Assert.assertFalse;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* {@link AbstractDiskHttpData} test cases
|
35 |
+
*/
|
36 |
+
public class AbstractDiskHttpDataTest {
|
37 |
+
|
38 |
+
@Test
|
39 |
+
public void testGetChunk() throws Exception {
|
40 |
+
TestHttpData test = new TestHttpData("test", UTF_8, 0);
|
41 |
+
try {
|
42 |
+
// BUG: CWE-378 Creation of Temporary File With Insecure Permissions
|
43 |
+
// File tmpFile = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
|
44 |
+
// FIXED:
|
45 |
+
File tmpFile = PlatformDependent.createTempFile(UUID.randomUUID().toString(), ".tmp", null);
|
46 |
+
tmpFile.deleteOnExit();
|
47 |
+
FileOutputStream fos = new FileOutputStream(tmpFile);
|
48 |
+
byte[] bytes = new byte[4096];
|
49 |
+
PlatformDependent.threadLocalRandom().nextBytes(bytes);
|
50 |
+
try {
|
51 |
+
fos.write(bytes);
|
52 |
+
fos.flush();
|
53 |
+
} finally {
|
54 |
+
fos.close();
|
55 |
+
}
|
56 |
+
test.setContent(tmpFile);
|
57 |
+
ByteBuf buf1 = test.getChunk(1024);
|
58 |
+
assertEquals(buf1.readerIndex(), 0);
|
59 |
+
assertEquals(buf1.writerIndex(), 1024);
|
60 |
+
ByteBuf buf2 = test.getChunk(1024);
|
61 |
+
assertEquals(buf2.readerIndex(), 0);
|
62 |
+
assertEquals(buf2.writerIndex(), 1024);
|
63 |
+
assertFalse("Arrays should not be equal",
|
64 |
+
Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)));
|
65 |
+
} finally {
|
66 |
+
test.delete();
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
private static final class TestHttpData extends AbstractDiskHttpData {
|
71 |
+
|
72 |
+
private TestHttpData(String name, Charset charset, long size) {
|
73 |
+
super(name, charset, size);
|
74 |
+
}
|
75 |
+
|
76 |
+
@Override
|
77 |
+
protected String getDiskFilename() {
|
78 |
+
return null;
|
79 |
+
}
|
80 |
+
|
81 |
+
@Override
|
82 |
+
protected String getPrefix() {
|
83 |
+
return null;
|
84 |
+
}
|
85 |
+
|
86 |
+
@Override
|
87 |
+
protected String getBaseDirectory() {
|
88 |
+
return null;
|
89 |
+
}
|
90 |
+
|
91 |
+
@Override
|
92 |
+
protected String getPostfix() {
|
93 |
+
return null;
|
94 |
+
}
|
95 |
+
|
96 |
+
@Override
|
97 |
+
protected boolean deleteOnExit() {
|
98 |
+
return false;
|
99 |
+
}
|
100 |
+
|
101 |
+
@Override
|
102 |
+
public HttpData copy() {
|
103 |
+
return null;
|
104 |
+
}
|
105 |
+
|
106 |
+
@Override
|
107 |
+
public HttpData duplicate() {
|
108 |
+
return null;
|
109 |
+
}
|
110 |
+
|
111 |
+
@Override
|
112 |
+
public HttpData retainedDuplicate() {
|
113 |
+
return null;
|
114 |
+
}
|
115 |
+
|
116 |
+
@Override
|
117 |
+
public HttpData replace(ByteBuf content) {
|
118 |
+
return null;
|
119 |
+
}
|
120 |
+
|
121 |
+
@Override
|
122 |
+
public HttpDataType getHttpDataType() {
|
123 |
+
return null;
|
124 |
+
}
|
125 |
+
|
126 |
+
@Override
|
127 |
+
public int compareTo(InterfaceHttpData o) {
|
128 |
+
return 0;
|
129 |
+
}
|
130 |
+
}
|
131 |
+
}
|