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

Configuration to enforce application scopes #1010

Conversation

talklittle
Copy link
Contributor

Fixes #1009


click_button 'Submit'
i_should_see 'Application created'
i_should_see 'My Application'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

fill_in 'doorkeeper_application[scopes]', with: ''

click_button 'Submit'
i_should_see 'Application created'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: ''

click_button 'Submit'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: ''

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: 'blahblah'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

config_is_set('enforce_configured_scopes', true)

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

scenario 'adding app validating bad scope' do
config_is_set('enforce_configured_scopes', true)

fill_in 'doorkeeper_application[name]', with: 'My Application'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

scenario 'adding app validating bad scope' do
config_is_set('enforce_configured_scopes', true)

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

feature 'Adding applications' do
context 'in application form' do
feature "Adding applications" do
context "in application form" do

Choose a reason for hiding this comment

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

Block has too many lines. [44/25]


feature 'Adding applications' do
context 'in application form' do
feature "Adding applications" do

Choose a reason for hiding this comment

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

Block has too many lines. [46/25]

@@ -1,94 +1,132 @@
require 'spec_helper_integration'
require "spec_helper_integration"

Choose a reason for hiding this comment

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

Missing magic comment # frozen_string_literal: true.

validates_each :scopes, if: :validate_configured_scopes? do |record, attr, value|
value_str = value.to_s
record.errors.add attr, :invalid_scope unless value_str.blank? or
ScopeChecker.valid?(value_str, Doorkeeper.configuration.scopes)

Choose a reason for hiding this comment

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

Align the operands of a condition in an unless statement spanning multiple lines.

@@ -14,6 +14,12 @@ module ApplicationMixin
validates :uid, uniqueness: true
validates :redirect_uri, redirect_uri: true

validates_each :scopes, if: :validate_configured_scopes? do |record, attr, value|
value_str = value.to_s
record.errors.add attr, :invalid_scope unless value_str.blank? or

Choose a reason for hiding this comment

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

Use || instead of or.

@@ -14,6 +14,12 @@ module ApplicationMixin
validates :uid, uniqueness: true
validates :redirect_uri, redirect_uri: true

validates_each :scopes, if: :validate_configured_scopes? do |record, attr, value|

Choose a reason for hiding this comment

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

Line is too long. [87/80]

@talklittle talklittle force-pushed the validate-application-scopes-configured branch from 12d0977 to b5b20c8 Compare January 3, 2018 05:01

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: 'blahblah'

click_button 'Submit'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: 'blahblah'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@talklittle talklittle force-pushed the validate-application-scopes-configured branch 2 times, most recently from a1592d0 to 750f361 Compare January 3, 2018 05:06
@nbulaj nbulaj added the bug? label Feb 4, 2018
@talklittle talklittle force-pushed the validate-application-scopes-configured branch from 750f361 to 08ae385 Compare February 15, 2018 05:06
@talklittle
Copy link
Contributor Author

@nbulaj Rebased to fix conflicts with master.

@talklittle talklittle force-pushed the validate-application-scopes-configured branch from 08ae385 to 558f167 Compare February 26, 2018 21:32
talklittle added a commit to talklittle/lobsters that referenced this pull request Feb 26, 2018
not yet merged into Doorkeeper as of 4.3.0,
so temporarily pointing to a git branch.

see doorkeeper-gem/doorkeeper#1010
@nbulaj nbulaj force-pushed the master branch 3 times, most recently from 14903a4 to 54e8345 Compare March 6, 2018 09:10
@talklittle talklittle force-pushed the validate-application-scopes-configured branch from 558f167 to d4782e8 Compare March 8, 2018 03:07
talklittle added a commit to talklittle/lobsters that referenced this pull request Mar 8, 2018
not yet merged into Doorkeeper as of 4.3.1,
so temporarily pointing to a git branch.

see doorkeeper-gem/doorkeeper#1010
@nbulaj nbulaj self-assigned this Mar 12, 2018
@nbulaj nbulaj added this to the 5.0 milestone Mar 12, 2018
@@ -12,6 +12,14 @@ class Application < ActiveRecord::Base
validates :uid, uniqueness: true
validates :redirect_uri, redirect_uri: true

validates_each :scopes, if: :enforce_scopes? do |record, attr, value|
Copy link
Member

Choose a reason for hiding this comment

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

Let's move it it from the validates_each to validate with custom method or just validate with a block (because validates_each is responsible for processing bunch of attributes, but we process only one - scopes).

@@ -12,6 +12,14 @@ class Application < ActiveRecord::Base
validates :uid, uniqueness: true
validates :redirect_uri, redirect_uri: true

validates_each :scopes, if: :enforce_scopes? do |record, attr, value|
valstr = value.to_s
Copy link
Member

Choose a reason for hiding this comment

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

No need to do to_s because ActiveModel / ActiveRecord already done type-casting for us.

@@ -12,6 +12,14 @@ class Application < ActiveRecord::Base
validates :uid, uniqueness: true
validates :redirect_uri, redirect_uri: true

validates_each :scopes, if: :enforce_scopes? do |record, attr, value|
valstr = value.to_s
unless valstr.blank? ||
Copy link
Member

Choose a reason for hiding this comment

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

Lets rewrite it to if - unless with more than one condition is hard to read and maintain.

end

scenario "adding app validating scope, blank scope is accepted" do
config_is_set("enforce_configured_scopes", true)
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a test with multiple scopes to be sure everything is OK

@nbulaj
Copy link
Member

nbulaj commented Mar 12, 2018

Hi @talklittle . Could you please take an attention to my comments below? Also could you please add an entry to NEWS.md file and squash all the commits to a single one? Thanks!

@nbulaj nbulaj added enhancement and removed bug? labels Mar 12, 2018
@talklittle talklittle force-pushed the validate-application-scopes-configured branch from d4782e8 to 588890c Compare March 14, 2018 07:23

scenario "adding app validating scope, bad scope with multiple scopes configured" do
config_is_set("enforce_configured_scopes", true)
config_is_set("optional_scopes", Doorkeeper::OAuth::Scopes.from_array(["read", "write", "admin"]))

Choose a reason for hiding this comment

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

Use %w or %W for an array of words.


scenario "adding app validating scope, multiple scopes configured" do
config_is_set("enforce_configured_scopes", true)
config_is_set("optional_scopes", Doorkeeper::OAuth::Scopes.from_array(["read", "write", "admin"]))

Choose a reason for hiding this comment

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

Use %w or %W for an array of words.

@@ -41,5 +43,15 @@ def generate_uid
def generate_secret
self.secret = UniqueToken.generate if secret.blank?
end

def validate_configured_scopes
if !scopes.blank? && !ScopeChecker.valid?(scopes.to_s, Doorkeeper.configuration.scopes)

Choose a reason for hiding this comment

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

Line is too long. [93/80]

@talklittle talklittle force-pushed the validate-application-scopes-configured branch from 588890c to 69c5a33 Compare March 14, 2018 07:27

def validate_configured_scopes
if !scopes.blank? &&
!ScopeChecker.valid?(scopes.to_s, Doorkeeper.configuration.scopes)

Choose a reason for hiding this comment

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

Align the operands of a condition in an if statement spanning multiple lines.


def validate_configured_scopes
if !scopes.blank? &&
!ScopeChecker.valid?(scopes.to_s, Doorkeeper.configuration.scopes)

Choose a reason for hiding this comment

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

Align the operands of a condition in an if statement spanning multiple lines.

@talklittle talklittle force-pushed the validate-application-scopes-configured branch from 69c5a33 to 80b8e06 Compare March 14, 2018 07:28
@talklittle
Copy link
Contributor Author

@nbulaj Thanks for review. Applied your feedback.

@talklittle talklittle force-pushed the validate-application-scopes-configured branch from 80b8e06 to bcb29d3 Compare March 14, 2018 20:08
@nbulaj nbulaj merged commit 829772b into doorkeeper-gem:master Mar 16, 2018
@nbulaj
Copy link
Member

nbulaj commented Mar 16, 2018

Thank you @talklittle 👍

talklittle added a commit to talklittle/lobsters that referenced this pull request Mar 28, 2018
not yet merged into Doorkeeper as of 4.3.1,
so temporarily pointing to a git branch.

see doorkeeper-gem/doorkeeper#1010
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.

3 participants