-
Notifications
You must be signed in to change notification settings - Fork 131
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
Resource server #77
Conversation
There was a problem hiding this 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/ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to resourceServerId
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to resourceServerId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
86e8997
to
3a3b9a7
Compare
|
3a3b9a7
to
801209c
Compare
|
There was a problem hiding this 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
andverificationLocation
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 theverificationKey
property.
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class Scope { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to isSystem
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this property.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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 :) |
There was a problem hiding this 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") |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one too
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
4cbb7cf
to
d1d09cd
Compare
BTW: serialization test revealed a bug 👍 |
Please let me know if this time it is ok - I will squash commits |
@mfarsikov Thanks for the contribution. I'll prepare a minor release with these changes. 🎉 |
Added
Resource server
CRUDFor ease building requests
RequestBuilder
was added, and refactored already existed Entities to use it.(Resource server API doc)