-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'alibaba:master' into master
- Loading branch information
Showing
4 changed files
with
91 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
|
@@ -20,7 +21,7 @@ | |
<connection>scm:git:[email protected]:alibaba/arthas.git</connection> | ||
<developerConnection>scm:git:[email protected]:alibaba/arthas.git</developerConnection> | ||
<url>https://github.com/alibaba/arthas</url> | ||
<tag>HEAD</tag> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<developers> | ||
|
@@ -81,7 +82,7 @@ | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<spring-boot.version>2.7.11</spring-boot.version> | ||
<spring-boot.version>2.7.14</spring-boot.version> | ||
<spring-boot3.version>3.0.6</spring-boot3.version> | ||
<maven-invoker-plugin.version>3.0.0</maven-invoker-plugin.version> | ||
<project.build.outputTimestamp>2020-09-27T15:10:43Z</project.build.outputTimestamp> | ||
|
@@ -94,7 +95,7 @@ | |
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>bytekit-core</artifactId> | ||
<version>0.0.8</version> | ||
<version>0.0.9</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.benf</groupId> | ||
|
@@ -449,7 +450,7 @@ | |
<artifactId>flatten-maven-plugin</artifactId> | ||
<version>1.2.2</version> | ||
<configuration> | ||
<flattenMode>minimum</flattenMode> | ||
<flattenMode>minimum</flattenMode> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tunnel-common/src/test/java/com/alibaba/arthas/tunnel/common/SimpleHttpResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.alibaba.arthas.tunnel.common; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InvalidClassException; | ||
import java.io.ObjectOutputStream; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
|
||
public class SimpleHttpResponseTest { | ||
|
||
@Test | ||
public void testSerialization() throws IOException, ClassNotFoundException { | ||
SimpleHttpResponse response = new SimpleHttpResponse(); | ||
response.setStatus(200); | ||
|
||
Map<String, String> headers = new HashMap<String, String>(); | ||
headers.put("Content-Type", "text/plain"); | ||
response.setHeaders(headers); | ||
|
||
String content = "Hello, world!"; | ||
response.setContent(content.getBytes()); | ||
|
||
byte[] bytes = SimpleHttpResponse.toBytes(response); | ||
|
||
SimpleHttpResponse deserializedResponse = SimpleHttpResponse.fromBytes(bytes); | ||
|
||
assertEquals(response.getStatus(), deserializedResponse.getStatus()); | ||
assertEquals(response.getHeaders(), deserializedResponse.getHeaders()); | ||
assertArrayEquals(response.getContent(), deserializedResponse.getContent()); | ||
} | ||
|
||
private static byte[] toBytes(Object object) throws IOException { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
try (ObjectOutputStream out = new ObjectOutputStream(bos)) { | ||
out.writeObject(object); | ||
out.flush(); | ||
return bos.toByteArray(); | ||
} | ||
} | ||
|
||
@Test(expected = InvalidClassException.class) | ||
public void testDeserializationWithUnauthorizedClass() throws IOException, ClassNotFoundException { | ||
Date date = new Date(); | ||
|
||
byte[] bytes = toBytes(date); | ||
|
||
// Try to deserialize the object with an unauthorized class | ||
// This should throw an InvalidClassException | ||
SimpleHttpResponse.fromBytes(bytes); | ||
} | ||
|
||
} |