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

Add scope property to policy #687

Merged

Conversation

piotr-dulikowski
Copy link
Contributor

An alternative to is_domain_owner (#686)

@piotr-dulikowski
Copy link
Contributor Author

Ran gofmt on policy.go and changed "pass" to "match (on)" in new tests.

schema/policy.go Outdated
func (policy *Policy) parseTokenScope(typeData map[string]interface{}) error {
if scopeRaw, ok := typeData["scope"]; ok {
var types []interface{}
if scope, ok := scopeRaw.(string); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a difference in semantics in string and 1-element array of strings? if not, wouldn't it be simpler to support just lists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no difference. I can remove support for single strings.

}

func (policy *Policy) parseTokenScope(typeData map[string]interface{}) error {
if scopeRaw, ok := typeData["scope"]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

flipping the if condition will reduce indents:

if scopeRaw, ok := typeData["scope"]; !ok {
    policy.tokenScope = allTokenTypes
    return nil
}

likewise in other places: in fact I prefer the style of

if fail() {
   return errFail
}

if otherFail() {
   return errOtherFail
}

//happy path follows

over

if !fail(){
    if !otherFail() {
        // happy path
    } else {
        return errOtherFail
    }
} else {
    return errFail
}


It("should fail to create when non-string is provided in scope list", func() {
givenPolicyWithScope([]interface{}{"admin", 123})
thenCreationShouldFail("Token type at position 1 in scope list should be a string")
})

It("should fail to create when invalid token type is provided", func() {
givenPolicyWithScope("flower")
It("should fail to create when a string is provided", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

fail because of a string (not list of strings) is covered in the second Entry of should fail to create when invalid value type is provided. here we're checking if creation fails because of an invalid value

@piotr-dulikowski
Copy link
Contributor Author

Squashed commits, waiting for CI

@piotr-dulikowski piotr-dulikowski merged commit 1bc4668 into cloudwan:master Oct 2, 2018
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.

4 participants