Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify user agent string #683

Merged
merged 8 commits into from
May 25, 2022
Merged

Conversation

sbansla
Copy link
Contributor

@sbansla sbansla commented May 19, 2022

Fixes

Standardisation of UserAgent String as per below mentioned doc
https://docs.google.com/document/d/1dDAvu9N4wkTnZKmWx5iiMfU42b7qYLAegA_QbZoBkU0/edit#

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

@sbansla sbansla changed the title Feature/modify user agent string feat: modify user agent string May 19, 2022
Copy link
Contributor

@childish-sambino childish-sambino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage is a bit low. Should see where more tests would be useful.

src/test/java/com/twilio/http/HttpUtilityTest.java Outdated Show resolved Hide resolved
src/test/java/com/twilio/http/HttpUtilityTest.java Outdated Show resolved Hide resolved
src/test/java/com/twilio/http/HttpUtilityTest.java Outdated Show resolved Hide resolved
src/test/java/com/twilio/http/HttpUtilityTest.java Outdated Show resolved Hide resolved
src/test/java/com/twilio/http/HttpUtilityTest.java Outdated Show resolved Hide resolved
@shrutiburman
Copy link
Contributor

Could you link the issue that this PR solves, in the description ?

@sbansla sbansla requested a review from shrutiburman May 20, 2022 05:46
new BasicHeader(HttpHeaders.ACCEPT, "application/json"),
new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "utf-8")
);
isCustomClient = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this flag? Would it ever equal to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is to know if client(developer) has created custom httpclient. I am using this flag to add " custom" String in UserAgentString.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I am missing something here. Won't it be always true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default it will be false, It will be true when NetworkHttpClient instance is created by using constructor:
"NetworkHttpClient(HttpClientBuilder clientBuilder)" (Means by passing custom HttpClientBuilder)

Example:
Check class ProxiedTwilioClientCreator in below mentioned link:
https://www.twilio.com/docs/libraries/java/custom-http-clients-java#

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks.

@sbansla
Copy link
Contributor Author

sbansla commented May 20, 2022

Could you link the issue that this PR solves, in the description ?

Added

Copy link
Contributor

@childish-sambino childish-sambino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level feedback on the new tests: they do execute the new/changed lines and have assertions, but the assertions are overly loose. They should assert on the expected impact of the new behavior rather than the new behavior not having a negative impact.

Let me know if you'd like to sync for more discussion/clarification.

src/test/java/com/twilio/TwilioTest.java Outdated Show resolved Hide resolved
src/test/java/com/twilio/http/NetworkHttpClientTest.java Outdated Show resolved Hide resolved
src/test/java/com/twilio/http/NetworkHttpClientTest.java Outdated Show resolved Hide resolved
src/test/java/com/twilio/http/TwilioRestClientTest.java Outdated Show resolved Hide resolved
private TwilioRestClient twilioRestClient;

@Injectable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this annotation is needed since setUp sets the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not able make method call without making variable as @Injectable
This was strange to me.

@sbansla
Copy link
Contributor Author

sbansla commented May 20, 2022

High-level feedback on the new tests: they do execute the new/changed lines and have assertions, but the assertions are overly loose. They should assert on the expected impact of the new behavior rather than the new behavior not having a negative impact.

Let me know if you'd like to sync for more discussion/clarification.

--->
Corrected the test cases wherever possible.
File: TwilioRestClientTest, I have marked variable twilioRestClientExtension as @Injectable. If I don't mark it as @Injectable, Execution of method won't happen.
twilioRestClientExtension.request(request) --> Won't succeed without @Injectable
This behaviour was strange to me.

Twilio.setPassword("Password");
Twilio.setUserAgentExtensions(Arrays.asList("ce-appointment-reminders/1.0.0", "code-exchange"));
Twilio.getRestClient();
assertEquals(Twilio.getUserAgentExtensions(), Arrays.asList("ce-appointment-reminders/1.0.0", "code-exchange"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should flip the arg order so it's expected, actual

Comment on lines 13 to 14
private List<String> userAgentExtensionsEmpty = new ArrayList<>();;
private List<String> userAgentExtensions = Arrays.asList("ce-appointment-reminders/1.0.0", "code-exchange");;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Double ; at EOL.

Comment on lines 42 to 83

@Test
public void testRequestWithExtention() {
Request request = new Request(
HttpMethod.GET,
Domains.API.toString(),
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json"
);
twilioRestClientExtension = new TwilioRestClient.Builder("AC123", "AUTH TOKEN")
.userAgentExtensions(userAgentStringExtensions)
.build();
twilioRestClientExtension.request(request);
assertEquals(request.getUserAgentExtensions(), userAgentStringExtensions);
}

@Test
public void testRequestWithExtentionEmpty() {
Request request = new Request(
HttpMethod.GET,
Domains.API.toString(),
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json"
);
twilioRestClientExtension = new TwilioRestClient.Builder("AC123", "AUTH TOKEN")
.userAgentExtensions(Arrays.asList())
.build();
twilioRestClientExtension.request(request);
assertEquals(request.getUserAgentExtensions(), null);
}

@Test
public void testRequestWithExtentionNull() {
Request request = new Request(
HttpMethod.GET,
Domains.API.toString(),
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json"
);
twilioRestClientExtension = new TwilioRestClient.Builder("AC123", "AUTH TOKEN")
.userAgentExtensions(null)
.build();
twilioRestClientExtension.request(request);
assertEquals(request.getUserAgentExtensions(), null);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Extention/Extension/

Request request = new Request(
HttpMethod.GET,
Domains.API.toString(),
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No need for string concatenation.

.userAgentExtensions(null)
.build();
twilioRestClientExtension.request(request);
assertEquals(request.getUserAgentExtensions(), null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: assertNull

Recommend installing the SonarQube IDE plugin which alerts about things like this.

Copy link
Contributor

@shrutiburman shrutiburman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@sonarcloud
Copy link

sonarcloud bot commented May 23, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

87.9% 87.9% Coverage
0.0% 0.0% Duplication

@sbansla sbansla merged commit 2c29bbe into main May 25, 2022
@sbansla sbansla deleted the feature/Modify-UserAgent-string branch May 25, 2022 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants