From aed77f6c8d647fea59b0dea3e344d3fec9d2f598 Mon Sep 17 00:00:00 2001 From: Tyler Long Date: Tue, 3 Oct 2023 15:04:20 -0700 Subject: [PATCH] Get rid of password flow in test cases --- .github/workflows/test.yml | 3 +-- dev-notes.md | 7 ------- .../com/ringcentral/AuthorizationTest.java | 6 +----- src/test/java/com/ringcentral/BinaryTest.java | 12 +++-------- .../java/com/ringcentral/CallLogTest.java | 6 +----- .../ringcentral/CheckSubscriptionTest.java | 6 +----- .../java/com/ringcentral/ConsumeTextTest.java | 13 ++---------- .../java/com/ringcentral/DictionaryTest.java | 12 ++--------- src/test/java/com/ringcentral/FaxTest.java | 6 +----- .../java/com/ringcentral/HttpEventTest.java | 6 +----- .../java/com/ringcentral/IVRContentTest.java | 18 +++-------------- .../java/com/ringcentral/LowLevelAPITest.java | 6 +----- src/test/java/com/ringcentral/MmsTest.java | 6 +----- .../ringcentral/ProvisionExtensionsTest.java | 6 +----- .../com/ringcentral/ProvisionIvrMenuTest.java | 6 +----- src/test/java/com/ringcentral/SmsTest.java | 12 ++--------- src/test/java/com/ringcentral/V2Test.java | 20 ------------------- 17 files changed, 22 insertions(+), 129 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d609951..970650a8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,6 @@ jobs: RINGCENTRAL_CLIENT_ID: ${{ secrets.RINGCENTRAL_CLIENT_ID }} RINGCENTRAL_CLIENT_SECRET: ${{ secrets.RINGCENTRAL_CLIENT_SECRET }} RINGCENTRAL_USERNAME: ${{ secrets.RINGCENTRAL_USERNAME }} - RINGCENTRAL_EXTENSION: ${{ secrets.RINGCENTRAL_EXTENSION }} - RINGCENTRAL_PASSWORD: ${{ secrets.RINGCENTRAL_PASSWORD }} + RINGCENTRAL_JWT_TOKEN: ${{ secrets.RINGCENTRAL_JWT_TOKEN }} RINGCENTRAL_RECEIVER: ${{ secrets.RINGCENTRAL_RECEIVER }} RINGCENTRAL_CALLEE: ${{ secrets.RINGCENTRAL_CALLEE }} diff --git a/dev-notes.md b/dev-notes.md index 49193332..88792d4a 100644 --- a/dev-notes.md +++ b/dev-notes.md @@ -1,10 +1,3 @@ -## Setup - -``` -cp src/test/resources/.env.sample src/test/resources/.env -edit src/test/resources/.env -``` - ## Test ``` diff --git a/src/test/java/com/ringcentral/AuthorizationTest.java b/src/test/java/com/ringcentral/AuthorizationTest.java index 529c8d87..6448894a 100644 --- a/src/test/java/com/ringcentral/AuthorizationTest.java +++ b/src/test/java/com/ringcentral/AuthorizationTest.java @@ -17,11 +17,7 @@ public void testAuthorize() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - TokenInfo token = rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + TokenInfo token = rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); assertNotNull(token.access_token); assertNotNull(rc.token); rc.revoke(); diff --git a/src/test/java/com/ringcentral/BinaryTest.java b/src/test/java/com/ringcentral/BinaryTest.java index 74acc50d..cfbcb091 100644 --- a/src/test/java/com/ringcentral/BinaryTest.java +++ b/src/test/java/com/ringcentral/BinaryTest.java @@ -17,12 +17,9 @@ public void uploadProfileImage() throws IOException, RestException { System.getenv("RINGCENTRAL_CLIENT_SECRET"), System.getenv("RINGCENTRAL_SERVER_URL")); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD")); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); - String str = rc.restapi().account().extension().profileImage().post(new + rc.restapi().account().extension().profileImage().post(new CreateUserProfileImageRequest() .image(new Attachment() .filename("test.png") @@ -40,10 +37,7 @@ public void downloadProfileImage() throws IOException, RestException { System.getenv("RINGCENTRAL_CLIENT_SECRET"), System.getenv("RINGCENTRAL_SERVER_URL")); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD")); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); byte[] bytes = rc.restapi().account().extension().profileImage("90x90").get(); diff --git a/src/test/java/com/ringcentral/CallLogTest.java b/src/test/java/com/ringcentral/CallLogTest.java index b4ac82bd..759204d7 100644 --- a/src/test/java/com/ringcentral/CallLogTest.java +++ b/src/test/java/com/ringcentral/CallLogTest.java @@ -17,11 +17,7 @@ public void listCallLogs() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); ReadUserCallLogParameters getParameters = new ReadUserCallLogParameters(); diff --git a/src/test/java/com/ringcentral/CheckSubscriptionTest.java b/src/test/java/com/ringcentral/CheckSubscriptionTest.java index de9df4e2..7b659a1f 100644 --- a/src/test/java/com/ringcentral/CheckSubscriptionTest.java +++ b/src/test/java/com/ringcentral/CheckSubscriptionTest.java @@ -17,11 +17,7 @@ public void listSubscriptions() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); SubscriptionListResource resp = rc.restapi().subscription().list(); for (SubscriptionInfo r : resp.records) { diff --git a/src/test/java/com/ringcentral/ConsumeTextTest.java b/src/test/java/com/ringcentral/ConsumeTextTest.java index 936e79bb..ee2697e3 100644 --- a/src/test/java/com/ringcentral/ConsumeTextTest.java +++ b/src/test/java/com/ringcentral/ConsumeTextTest.java @@ -13,19 +13,10 @@ public void updateGlipPostText() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); String groupId = rc.teamMessaging().v1().chats().list().records[0].id; - String postId = rc.teamMessaging().v1().chats(groupId).posts().list().records[0].id; - - // below is for experiment only -// String newText = UUID.randomUUID().toString(); -// String updatedText = rc.restapi().glip().groups(groupId).posts(postId).text().put(newText); -// assertEquals(updatedText, newText); + rc.teamMessaging().v1().chats(groupId).posts().list(); rc.revoke(); } diff --git a/src/test/java/com/ringcentral/DictionaryTest.java b/src/test/java/com/ringcentral/DictionaryTest.java index 0c788c0f..6f34020b 100644 --- a/src/test/java/com/ringcentral/DictionaryTest.java +++ b/src/test/java/com/ringcentral/DictionaryTest.java @@ -16,11 +16,7 @@ public void testGetCountry() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); CountryInfoDictionaryModel c = rc.restapi().dictionary().country("46").get(); Assert.assertEquals("China", c.name); @@ -36,11 +32,7 @@ public void testListCountry() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); CountryListDictionaryModel r = rc.restapi().dictionary().country().list(); Assert.assertTrue(r.records.length > 0); diff --git a/src/test/java/com/ringcentral/FaxTest.java b/src/test/java/com/ringcentral/FaxTest.java index 63903ed2..7ab1bbdf 100644 --- a/src/test/java/com/ringcentral/FaxTest.java +++ b/src/test/java/com/ringcentral/FaxTest.java @@ -22,11 +22,7 @@ public void sendFax() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); FaxResponse r = rc.restapi().account().extension().fax().post( new CreateFaxMessageRequest() diff --git a/src/test/java/com/ringcentral/HttpEventTest.java b/src/test/java/com/ringcentral/HttpEventTest.java index 90e25ae2..7cabdc03 100644 --- a/src/test/java/com/ringcentral/HttpEventTest.java +++ b/src/test/java/com/ringcentral/HttpEventTest.java @@ -18,11 +18,7 @@ public void afterHttpCall() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); final int[] count = {0}; rc.httpEventListeners.add((response, request) -> { diff --git a/src/test/java/com/ringcentral/IVRContentTest.java b/src/test/java/com/ringcentral/IVRContentTest.java index ad280684..368192f1 100644 --- a/src/test/java/com/ringcentral/IVRContentTest.java +++ b/src/test/java/com/ringcentral/IVRContentTest.java @@ -17,11 +17,7 @@ public void downloadIVRPromptContent() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); IvrPrompts ivrPrompts = rc.restapi().account().ivrPrompts().list(); PromptInfo promptInfo = rc.restapi().account().ivrPrompts(ivrPrompts.records[0].id).get(); @@ -41,11 +37,7 @@ public void createIVRPromptContent() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); rc.restapi().account().ivrPrompts().post(new CreateIVRPromptRequest() .name("Uploaded via API") @@ -66,11 +58,7 @@ public void updateIVRPromptContent() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); IvrPrompts ivrPrompts = rc.restapi().account().ivrPrompts().list(); PromptInfo promptInfo = rc.restapi().account().ivrPrompts(ivrPrompts.records[0].id).get(); diff --git a/src/test/java/com/ringcentral/LowLevelAPITest.java b/src/test/java/com/ringcentral/LowLevelAPITest.java index da733995..f7c1a4ec 100644 --- a/src/test/java/com/ringcentral/LowLevelAPITest.java +++ b/src/test/java/com/ringcentral/LowLevelAPITest.java @@ -17,11 +17,7 @@ public void testParseObject() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); ResponseBody responseBody = rc.get("/restapi/v1.0/account/~/extension/~", null); String responseString = responseBody.string(); GetExtensionInfoResponse extensionInfo = Utils.gson.fromJson(responseString, GetExtensionInfoResponse.class); diff --git a/src/test/java/com/ringcentral/MmsTest.java b/src/test/java/com/ringcentral/MmsTest.java index 406246db..2c479dc5 100644 --- a/src/test/java/com/ringcentral/MmsTest.java +++ b/src/test/java/com/ringcentral/MmsTest.java @@ -22,11 +22,7 @@ public void sendMms() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); GetSMSMessageInfoResponse response = rc.restapi().account().extension().mms().post( new CreateMMSMessage() diff --git a/src/test/java/com/ringcentral/ProvisionExtensionsTest.java b/src/test/java/com/ringcentral/ProvisionExtensionsTest.java index 2f873c04..c022877c 100644 --- a/src/test/java/com/ringcentral/ProvisionExtensionsTest.java +++ b/src/test/java/com/ringcentral/ProvisionExtensionsTest.java @@ -18,11 +18,7 @@ public void CreateAndDeleteExtension() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); rc.httpEventListeners.add((response, request) -> { String message = Utils.formatHttpMessage(response, request); diff --git a/src/test/java/com/ringcentral/ProvisionIvrMenuTest.java b/src/test/java/com/ringcentral/ProvisionIvrMenuTest.java index d0fba643..ff31316f 100644 --- a/src/test/java/com/ringcentral/ProvisionIvrMenuTest.java +++ b/src/test/java/com/ringcentral/ProvisionIvrMenuTest.java @@ -16,11 +16,7 @@ public void CreateAndDeleteIVRMenu() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); IVRMenuInfo iVRMenuInfo = rc.restapi().account().ivrMenus().post(new IVRMenuInfo().extensionNumber("2002").name("My IVR menu")); assertNotNull(iVRMenuInfo); diff --git a/src/test/java/com/ringcentral/SmsTest.java b/src/test/java/com/ringcentral/SmsTest.java index 1f60b03a..eebec3d5 100644 --- a/src/test/java/com/ringcentral/SmsTest.java +++ b/src/test/java/com/ringcentral/SmsTest.java @@ -19,11 +19,7 @@ public void sendSms() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); GetSMSMessageInfoResponse response = rc.restapi().account().extension().sms().post( new CreateSMSMessage() @@ -48,11 +44,7 @@ public void sendSms2() throws IOException, RestException { System.getenv("RINGCENTRAL_SERVER_URL") ); - rc.authorize( - System.getenv("RINGCENTRAL_USERNAME"), - System.getenv("RINGCENTRAL_EXTENSION"), - System.getenv("RINGCENTRAL_PASSWORD") - ); + rc.authorize(System.getenv("RINGCENTRAL_JWT_TOKEN")); CreateSMSMessage requestBody = new CreateSMSMessage(); requestBody.text = "hello world"; diff --git a/src/test/java/com/ringcentral/V2Test.java b/src/test/java/com/ringcentral/V2Test.java index 696ccf1e..51702b82 100644 --- a/src/test/java/com/ringcentral/V2Test.java +++ b/src/test/java/com/ringcentral/V2Test.java @@ -16,25 +16,5 @@ public void GetAccountInfo() throws IOException, RestException { ); String path = rc.restapi().v2().accounts().path(); Assert.assertEquals("/restapi/v2/accounts/~", path); -// -// rc.authorize( -// System.getenv("RINGCENTRAL_USERNAME"), -// System.getenv("RINGCENTRAL_EXTENSION"), -// System.getenv("RINGCENTRAL_PASSWORD") -// ); -// -// GetSMSMessageInfoResponse response = rc.restapi().account().extension().sms().post( -// new CreateSMSMessage() -// .text("hello world") -// .from(new MessageStoreCallerInfoRequest().phoneNumber(System.getenv("RINGCENTRAL_USERNAME"))) -// .to(new MessageStoreCallerInfoRequest[]{ -// new MessageStoreCallerInfoRequest().phoneNumber(System.getenv("RINGCENTRAL_RECEIVER")) -// }) -// ); -// assertNotNull(response); -// assertNotNull(response.subject); -// assertTrue(response.subject.contains("hello world")); -// -// rc.revoke(); } }