diff --git a/README.en-US.md b/README.en-US.md index bb037cd6f4870ce40f235a84491b6cac515fcb3e..6905b90850cfa332daf101e0a627b56fbd9db3c1 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -70,6 +70,11 @@
diff --git a/src/test/java/me/zhyd/oauth/request/AuthExtendRequestTest.java b/src/test/java/me/zhyd/oauth/request/AuthExtendRequestTest.java
index c1184c25573c43182bc5c3a0206681cd7eccb392..765881d5c26bd9775533110e7fbc98a2136402c6 100644
--- a/src/test/java/me/zhyd/oauth/request/AuthExtendRequestTest.java
+++ b/src/test/java/me/zhyd/oauth/request/AuthExtendRequestTest.java
@@ -41,9 +41,10 @@ public class AuthExtendRequestTest {
String state = AuthStateUtils.createState();
request.authorize(state);
- AuthCallback callback = new AuthCallback();
- callback.setCode("code");
- callback.setState(state);
+ AuthCallback callback = AuthCallback.builder()
+ .code("code")
+ .state(state)
+ .build();
AuthResponse response = request.login(callback);
Assert.assertNotNull(response);
diff --git a/src/test/java/me/zhyd/oauth/utils/GlobalAuthUtilTest.java b/src/test/java/me/zhyd/oauth/utils/GlobalAuthUtilTest.java
index 65f0c15254be674065eb668fcaca886d105e81e6..ce2a476ba8c7aa62154e3d9d9f8127aa4f996564 100644
--- a/src/test/java/me/zhyd/oauth/utils/GlobalAuthUtilTest.java
+++ b/src/test/java/me/zhyd/oauth/utils/GlobalAuthUtilTest.java
@@ -1,36 +1,40 @@
package me.zhyd.oauth.utils;
+import me.zhyd.oauth.config.AuthConfig;
+import me.zhyd.oauth.model.AuthCallback;
+import me.zhyd.oauth.model.AuthToken;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
+import static me.zhyd.oauth.config.AuthDefaultSource.TWITTER;
+import static me.zhyd.oauth.utils.GlobalAuthUtil.generateTwitterSignature;
+import static me.zhyd.oauth.utils.GlobalAuthUtil.urlEncode;
+import static org.junit.Assert.assertEquals;
+
public class GlobalAuthUtilTest {
@Test
public void testGenerateDingTalkSignature() {
- Assert.assertEquals("mLTZEMqIlpAA3xtJ43KcRT0EDLwgSamFe%2FNis5lq9ik%3D",
- GlobalAuthUtil.generateDingTalkSignature(
- "SHA-256", "1562325753000 "));
+ assertEquals("mLTZEMqIlpAA3xtJ43KcRT0EDLwgSamFe%2FNis5lq9ik%3D",
+ GlobalAuthUtil.generateDingTalkSignature("SHA-256", "1562325753000 "));
}
@Test
public void testUrlDecode() {
- Assert.assertEquals("", GlobalAuthUtil.urlDecode(null));
- Assert.assertEquals("https://www.foo.bar",
- GlobalAuthUtil.urlDecode("https://www.foo.bar"));
- Assert.assertEquals("mLTZEMqIlpAA3xtJ43KcRT0EDLwgSamFe/Nis5lq9ik=",
- GlobalAuthUtil.urlDecode(
- "mLTZEMqIlpAA3xtJ43KcRT0EDLwgSamFe%2FNis5lq9ik%3D"));
+ assertEquals("", GlobalAuthUtil.urlDecode(null));
+ assertEquals("https://www.foo.bar", GlobalAuthUtil.urlDecode("https://www.foo.bar"));
+ assertEquals("mLTZEMqIlpAA3xtJ43KcRT0EDLwgSamFe/Nis5lq9ik=",
+ GlobalAuthUtil.urlDecode("mLTZEMqIlpAA3xtJ43KcRT0EDLwgSamFe%2FNis5lq9ik%3D"));
}
@Test
public void testParseStringToMap() {
Map expected = new HashMap();
expected.put("bar", "baz");
- Assert.assertEquals(expected,
- GlobalAuthUtil.parseStringToMap("foo&bar=baz"));
+ assertEquals(expected, GlobalAuthUtil.parseStringToMap("foo&bar=baz"));
}
@Test
@@ -46,8 +50,7 @@ public class GlobalAuthUtilTest {
Assert.assertFalse(GlobalAuthUtil.isHttpsProtocol(""));
Assert.assertFalse(GlobalAuthUtil.isHttpsProtocol("foo"));
- Assert.assertTrue(
- GlobalAuthUtil.isHttpsProtocol("https://www.foo.bar"));
+ Assert.assertTrue(GlobalAuthUtil.isHttpsProtocol("https://www.foo.bar"));
}
@Test
@@ -58,4 +61,90 @@ public class GlobalAuthUtilTest {
Assert.assertTrue(GlobalAuthUtil.isLocalHost("127.0.0.1"));
Assert.assertTrue(GlobalAuthUtil.isLocalHost("localhost"));
}
+
+ @Test
+ public void testGenerateTwitterSignatureForRequestToken() {
+ AuthConfig config = AuthConfig.builder()
+ .clientId("HD0XLqzi5Wz0G08rh45Cg8mgh")
+ .clientSecret("0YX3RH2DnPiT77pgzLzFdfpMKX8ENLIWQKYQ7lG5TERuZNgXN5")
+ .redirectUri("https://codinglife.tech")
+ .build();
+ Map