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

Resource server #77

Merged
merged 4 commits into from
Dec 7, 2017
Merged

Resource server #77

merged 4 commits into from
Dec 7, 2017

Conversation

mfarsikov
Copy link
Contributor

Added Resource server CRUD

For ease building requests RequestBuilder was added, and refactored already existed Entities to use it.

(Resource server API doc)

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

Hey. Thanks for your contribution! Overall it looks good. Apart from the comments I left you, I'll need 2 big things:

  • Please keep the main purpose of the PR and remove the refactor of the Request creation and handling. You can move those commits to a separate PR if you want, but they add noise here.
  • Please add the missing tests as some endpoints are not tested.

Once assorted, I'll carefully check each endpoint against the server to see if we're missing any required parameters.
Cheers

.gitignore Outdated
@@ -101,6 +101,7 @@ gradle-app.setting
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
/.idea/
Copy link
Contributor

Choose a reason for hiding this comment

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

We decided to keep some of the idea files, by using the "intellij+iml" configuration provided by gitignore.io. Remove this line please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

@Override
public String toString() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this method as we chose not to provide it on the other entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

@Override
public String toString() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this method as we chose not to provide it on the other entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

public class ResourceServerEntityTest extends BaseMgmtEntityTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

More tests should be added to cover all the new methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@JsonProperty("is_system")
private Boolean isSystem;

public ResourceServer() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember if this constructor must exist because of Jackson, see if it can be removed. Also we need a constructor that receives at least the identifier parameter as that's the only required parameter when creating a new ResourceServer instance to post. id will always be returned by the server, but I trust Jackson is going to handle it just fine 😄 . (Add those tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default constructor removed.
As I understand JSON transformation is covered in ResourceServerEntityTest when content of resource_servers_list.json is converted to ResourceServer instances. Do we nee additional tests for JSON conversion?

* Cretes request for fetching single resource server by it's ID.
* See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers_by_id>API documentation</a>
*
* @param id {@link ResourceServer#identifier} field
Copy link
Contributor

Choose a reason for hiding this comment

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

id and identifier are different properties of a ResourceServer. My guess is that the id is the one the server assigns when it's created, and the identifier is the name we choose for it (like "myapp.auth0.com"). An identifier is required when creating the ResourceServer while the id is always returned when listing/getting resource servers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed

* @param id {@link ResourceServer#identifier} field
* @return request to execute
*/
public Request<ResourceServer> get(String id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to resourceServerId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* @param id {@link ResourceServer#identifier} field
* @return request to execute
*/
public Request<Void> delete(String id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to resourceServerId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mfarsikov mfarsikov force-pushed the resource-server branch 2 times, most recently from 86e8997 to 3a3b9a7 Compare November 24, 2017 19:45
@lbalmaceda
Copy link
Contributor

RequestBuilder and RequestUnderConstruction classes are still there.. Please remove them and just add the Resource Server entity and its tests.

@mfarsikov
Copy link
Contributor Author

RequestBuilder removed :(

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

@mfarsikov Thanks. Like I said, feel free to submit those improvements in a separate PR and I'll review them in the future. I've some new feedback for you:

  • Test setters as coverage complains you're not testing them.
  • I've doubts with verificationKey and verificationLocation and can't make the server return them, maybe they are just set on creation. I'll ask the team to verify they are correct. Edit: Added a comment to remove the verificationKey property.

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class Scope {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add these annotations at the class level

@SuppressWarnings("WeakerAccess", "unused")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

private Boolean allowOfflineAccess;
@JsonProperty("skip_consent_for_verifiable_first_party_clients")
private Boolean skipConsentForVerifiableFirstPartyClients;
@JsonProperty("token_lifetime")
Copy link
Contributor

Choose a reason for hiding this comment

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

It's missing the "token_lifetime_for_web" property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResourceServer {
@JsonProperty
Copy link
Contributor

Choose a reason for hiding this comment

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

add the explicit property name in the annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

public class ResourceServer {
@JsonProperty
private String id;
@JsonProperty
Copy link
Contributor

Choose a reason for hiding this comment

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

add the explicit property name in the annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@JsonProperty("scopes")
private List<Scope> scopes;
@JsonProperty("signing_alg")
private String signingAlg;
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to signingAlgorithm (same for getters/setters)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

@JsonCreator
public ResourceServer(@JsonProperty("id") String id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this constructor as the only required field is "identifier". Add another one with no-args, since when you need to PATCH the resource server you can't specify the "identifier".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@JsonProperty("is_system")
private Boolean isSystem;

public ResourceServer(String identifier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Annotate this constructor with @JsonCreator and add the @JsonProperty annotation to the "identifier" parameter.

return identifier;
}

public void setIdentifier(String identifier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this setter as it cannot change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this.name = name;
}

public Boolean getIsSystem() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to isSystem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

private String value;

@JsonCreator
public Scope(@JsonProperty("value") String value,
Copy link
Contributor

Choose a reason for hiding this comment

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

Value is the only required property. Let's have a single constructor with value instead of both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@JsonProperty("token_lifetime")
private Integer tokenLifetime;
@JsonProperty("verificationKey")
private String verificationKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return isSystem;
}

public void setIsSystem(Boolean system) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove setter as I'm not sure this works. It's easier to add it later 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* @param resourceServerId {@link ResourceServer#id} field
* @return request to execute
*/
public Request<ResourceServer> get(String resourceServerId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

All these entity methods that have a resourceServerId as a parameter, I'm checking the API docs and it says that it could be either the id or the identifier (audience) value. Assert this is true and in that case, rename to resourceServerIdOrIdentifier and explain this in the javadoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mfarsikov
Copy link
Contributor Author

Regarding testing setters: I would not recommend to create "cargo cult" around test-coverage.

I not sure but it should be possible to exclude data-classes from coverage testing.

Thank you for your patience :)

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

I agree with your comment about the test coverage but in this case, the serialization is not being tested completely neither in the client not in the pojo tests. I decided to make simpler the tests on the client by just checking the body size (in parameters count) and test the serialization in a separate pojo test, because jackson uses annotations to handle this. I've left you some final comments. Thanks

private String name;
@JsonProperty("identifier")
private String identifier;
@JsonProperty("scopes")
private List<Scope> scopes;
@JsonProperty("signing_alg")
private String signingAlg;
@JsonProperty("signing_algorithm")
Copy link
Contributor

Choose a reason for hiding this comment

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

the json property was correct signing_alg, what changes is the pojo field name (the line below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

public void setScopes(List<Scope> scopes) {
this.scopes = scopes;
}

public String getSigningAlg() {
return signingAlg;
@JsonProperty("signing_algorithm")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to also fix this json property name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

public void setSigningAlg(String signingAlg) {
this.signingAlg = signingAlg;
@JsonProperty("signing_algorithm")
Copy link
Contributor

Choose a reason for hiding this comment

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

And this one too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -42,22 +42,18 @@ public void shouldListResourceServers() throws Exception {

@Test
public void shouldUpdateResourceServer() throws Exception {
ResourceServer resourceServer = new ResourceServer("https://api.my-company.com/api/v2/");
resourceServer.setId("23445566abab");
Copy link
Contributor

Choose a reason for hiding this comment

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

Just keep the new instance line, the pojo class serialization should be tested in a separate file as we did for the rest of them. The scope description serialization for example is never tested. Check the test/com/auth0/json/mgmt folder for examples and please add one class for each pojo. You can remove the call to the setters on this "shouldUpdateResourceServer" test.

@mfarsikov
Copy link
Contributor Author

BTW: serialization test revealed a bug 👍

@mfarsikov
Copy link
Contributor Author

Please let me know if this time it is ok - I will squash commits

@lbalmaceda lbalmaceda merged commit 424f99c into auth0:master Dec 7, 2017
@lbalmaceda
Copy link
Contributor

@mfarsikov Thanks for the contribution. I'll prepare a minor release with these changes. 🎉

@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.5.0 Dec 7, 2017
@mfarsikov mfarsikov deleted the resource-server branch December 7, 2017 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants