Skip to content

Commit d7fd2c6

Browse files
committed
add test
1 parent 7c8ed1a commit d7fd2c6

File tree

6 files changed

+110
-15
lines changed

6 files changed

+110
-15
lines changed

springboot-starter-security-jwt/src/test/resources/application.properties

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,27 @@ server.port=8088
33
codingapi.security.jwt-time=10000
44
codingapi.security.jwt-rest-time=5000
55

6+
# JWT密钥 需大于32位的字符串
7+
codingapi.security.jwt-secret=codingapi.security.jwt.secretkey
8+
# JWT AES密钥
9+
codingapi.security.ase-key=QUNEWCQlXiYqJCNYQ1phc0FDRFgkJV4mKiQjWENaYXM=
10+
# JWT AES IV
11+
codingapi.security.aes-iv=QUNYRkdIQEVEUyNYQ1phcw==
12+
13+
# JWT 有效时间(毫秒) 15分钟有效期 1000*60*15=900000
14+
codingapi.security.jwt-time=900000
15+
# JWT 更换令牌时间(毫秒) 10分钟后更换令牌 1000*60*10=600000
16+
codingapi.security.jwt-rest-time=600000
17+
18+
# Security 配置 请求权限拦截地址
19+
codingapi.security.authenticated-urls=/api/**
20+
# Security 配置 登录地址
21+
codingapi.security.login-processing-url=/api/login
22+
# Security 配置 登出地址
23+
codingapi.security.logout-url=/api/logout
24+
# Security 配置 不拦截的地址
25+
codingapi.security.ignore-urls=/open/**
26+
# 禁用CSRF
27+
codingapi.security.disable-csrf=true
28+
# 禁用CORS
29+
codingapi.security.disable-cors=true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.codingapi.springboot.framework.crypto;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.security.NoSuchAlgorithmException;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class DESTest {
10+
11+
@Test
12+
void getKey() throws NoSuchAlgorithmException {
13+
DES des = new DES();
14+
byte[] key = des.getKey();
15+
assertNotNull(key);
16+
}
17+
18+
@Test
19+
void encryptAndDecrypt() throws Exception {
20+
DES des = new DES();
21+
String word = "123";
22+
byte[] encrypt = des.encrypt(word.getBytes());
23+
byte[] decrypt = des.decrypt(encrypt);
24+
assertEquals(word,new String(decrypt));
25+
}
26+
27+
}
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
package com.codingapi.springboot.framework.crypto;
22

3-
import lombok.extern.slf4j.Slf4j;
43
import org.junit.jupiter.api.Test;
54

6-
import java.nio.charset.StandardCharsets;
5+
import java.security.NoSuchAlgorithmException;
6+
import java.util.Base64;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.*;
99

10-
@Slf4j
1110
class RSATest {
1211

1312
@Test
14-
void encode() throws Exception {
15-
String word = "123";
16-
String encode = RSAUtils.getInstance().encode(word);
17-
log.info("encode:{}",encode);
18-
String decode = RSAUtils.getInstance().decode(encode);
19-
assertEquals(word,decode,"AES encode error");
13+
void getPrivateKey() throws NoSuchAlgorithmException {
14+
RSA rsa = new RSA();
15+
assertNotNull(rsa.getPrivateKey());
16+
Base64.Encoder encoder = Base64.getEncoder();
17+
System.out.println("privateKey:" + encoder.encodeToString(rsa.getPrivateKey()));
2018
}
2119

2220
@Test
23-
void decode() throws Exception {
24-
byte[] word = "123".getBytes(StandardCharsets.UTF_8);
25-
byte[] encode = RSAUtils.getInstance().encode(word);
26-
byte[] decode = RSAUtils.getInstance().decode(encode);
27-
assertEquals(new String(word),new String(decode),"AES encode error");
21+
void getPublicKey() throws NoSuchAlgorithmException {
22+
RSA rsa = new RSA();
23+
assertNotNull(rsa.getPublicKey());
24+
Base64.Encoder encoder = Base64.getEncoder();
25+
System.out.println("publicKey:" + encoder.encodeToString(rsa.getPublicKey()));
2826
}
27+
28+
@Test
29+
void encryptAndDecrypt() throws Exception {
30+
RSA rsa = new RSA();
31+
String content = "hello world";
32+
byte[] encrypt = rsa.encrypt(content.getBytes());
33+
byte[] data = rsa.decrypt(encrypt);
34+
assertEquals(content,new String(data));
35+
}
36+
2937
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.codingapi.springboot.framework.crypto;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.nio.charset.StandardCharsets;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
@Slf4j
11+
class RSAUtilsTest {
12+
13+
@Test
14+
void encode() throws Exception {
15+
String word = "123";
16+
String encode = RSAUtils.getInstance().encode(word);
17+
log.info("encode:{}",encode);
18+
String decode = RSAUtils.getInstance().decode(encode);
19+
assertEquals(word,decode,"AES encode error");
20+
}
21+
22+
@Test
23+
void decode() throws Exception {
24+
byte[] word = "123".getBytes(StandardCharsets.UTF_8);
25+
byte[] encode = RSAUtils.getInstance().encode(word);
26+
byte[] decode = RSAUtils.getInstance().decode(encode);
27+
assertEquals(new String(word),new String(decode),"AES encode error");
28+
}
29+
}

springboot-starter/src/test/java/com/codingapi/springboot/framework/dto/request/PageRequestTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ void test(){
1515
assertEquals(pageRequest.getCurrent(),1);
1616
assertEquals(pageRequest.getPageSize(),10);
1717
}
18+
19+
20+
1821
}

springboot-starter/src/test/java/com/codingapi/springboot/framework/handler/DemoChangeLogHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ public void handler(DemoChangeEvent event) {
1212
log.info("print before name :{},current name :{}", event.getBeforeName(), event.getCurrentName());
1313
}
1414

15+
@Override
16+
public void error(Exception exception) {
17+
log.error("DemoChangeLogHandler error", exception);
18+
}
1519
}

0 commit comments

Comments
 (0)