-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from sebastjan-hribar/add_app_module_to_policies
Add app module to policies
- Loading branch information
Showing
11 changed files
with
297 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
rokku (0.6.2) | ||
rokku (0.7.0) | ||
hanami-controller (~> 1.0) | ||
hanami-router (~> 1.0) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Rokku | ||
VERSION = "0.6.2" | ||
VERSION = "0.7.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,119 @@ | ||
require 'test_helper' | ||
require_relative '../lib/rokku/commands/commands.rb' | ||
require_relative 'testApp/lib/firstApp/policies/TaskPolicy.rb' | ||
require_relative 'testApp/lib/web/policies/TaskPolicy.rb' | ||
require_relative 'testApp/lib/admin/policies/TaskPolicy.rb' | ||
include Commands | ||
|
||
describe 'Authorization' do | ||
before do | ||
@application_name = 'firstApp' | ||
@action = Web::Controllers::Task::New.new | ||
@controller_name = @action.controller_name.split("::")[2] | ||
@action_name = @action.controller_name.split("::")[3] | ||
@action_web = Web::Controllers::Task::New.new | ||
@app_name_web = @action_web.controller_name.split("::")[0] | ||
@controller_name_web = @action_web.controller_name.split("::")[2] | ||
@action_name_web = @action_web.controller_name.split("::")[3] | ||
|
||
@action_admin = Admin::Controllers::Task::New.new | ||
@app_name_admin = @action_admin.controller_name.split("::")[0] | ||
@controller_name_admin = @action_admin.controller_name.split("::")[2] | ||
@action_name_admin = @action_admin.controller_name.split("::")[3] | ||
end | ||
|
||
describe 'with authorized user and one role as a string' do | ||
describe 'with authorized user and one role as a string for Web-Task-New' do | ||
before do | ||
@user = User.new(id: 1, name: 'Tester', hashed_pass: '123', | ||
roles: 'level_one_user') | ||
@roles = @user.roles | ||
end | ||
end | ||
|
||
after do | ||
@user = nil | ||
end | ||
|
||
it 'authorizes the user' do | ||
assert authorized?(@controller_name, @action_name), 'User is authorized' | ||
assert authorized?(@app_name_web, @controller_name_web, @action_name_web), 'User is authorized' | ||
end | ||
end | ||
|
||
describe 'with authorized user and roles as an array of roles' do | ||
before do | ||
@user = User.new(id: 1, name: 'Tester', hashed_pass: '123', | ||
roles: ['level_one_user', 'level_two_user']) | ||
@roles = @user.roles | ||
end | ||
describe 'with authorized user and roles as an array of roles for Web-Task-New' do | ||
before do | ||
@user = User.new(id: 1, name: 'Tester', hashed_pass: '123', | ||
roles: ['level_one_user', 'level_two_user']) | ||
@roles = @user.roles | ||
end | ||
|
||
after do | ||
@user = nil | ||
end | ||
after do | ||
@user = nil | ||
end | ||
|
||
it 'authorizes the user' do | ||
assert authorized?(@controller_name, @action_name), 'User is authorized' | ||
end | ||
end | ||
it 'authorizes the user' do | ||
assert authorized?(@app_name_web, @controller_name_web, @action_name_web), 'User is authorized' | ||
end | ||
end | ||
|
||
describe 'with unauthorized user' do | ||
before do | ||
@user = User.new(id: 1, name: 'Tester', hashed_pass: '123', roles: 'guest_user') | ||
end | ||
describe 'with unauthorized user' do | ||
before do | ||
@user = User.new(id: 1, name: 'Tester', hashed_pass: '123', roles: 'guest_user') | ||
end | ||
|
||
after do | ||
@user = nil | ||
end | ||
after do | ||
@user = nil | ||
end | ||
|
||
it 'doesnt authorize the user' do | ||
refute authorized?(@controller_name, @action_name), 'User is not authorized' | ||
end | ||
end | ||
it 'doesnt authorize the user' do | ||
refute authorized?(@app_name_web, @controller_name_web, @action_name_web), 'User is not authorized' | ||
end | ||
end | ||
|
||
describe 'policy file creation' do | ||
before do | ||
@new_controller = 'Post' | ||
end | ||
describe 'with authorized user and roles as an array of roles for Admin-Task-New' do | ||
before do | ||
@user = User.new(id: 1, name: 'Tester', hashed_pass: '123', | ||
roles: ['level_two_user', 'level_three_user']) | ||
@roles = @user.roles | ||
end | ||
|
||
after do | ||
Dir.chdir('test/testApp') do | ||
File.delete("lib/#{@application_name}/policies/#{@new_controller}Policy.rb") | ||
end | ||
end | ||
after do | ||
@user = nil | ||
end | ||
|
||
it 'generates policy' do | ||
Dir.chdir('test/testApp') do | ||
Commands.generate_policy(@application_name, @new_controller) | ||
generated_policy_string = "lib/#{@application_name}/policies/#{@new_controller}Policy.rb" | ||
assert File.file?("lib/#{@application_name}/policies/#{@new_controller}Policy.rb"), "The file lib/#{@application_name}/policies/#{@new_controller}Policy.rb is generated" | ||
assert File.readlines(generated_policy_string).grep(/authorized_roles_for_new/).size > 0, 'The file has content authorized_roles_for_new.' | ||
end | ||
end | ||
it 'authorizes the user' do | ||
assert authorized?(@app_name_admin, @controller_name_admin, @action_name_admin), 'User is authorized' | ||
end | ||
end | ||
|
||
describe 'with unauthorized user' do | ||
before do | ||
@user = User.new(id: 1, name: 'Tester', hashed_pass: '123', roles: 'guest_user') | ||
end | ||
|
||
after do | ||
@user = nil | ||
end | ||
|
||
it 'doesnt authorize the user' do | ||
refute authorized?(@app_name_admin, @controller_name_admin, @action_name_admin), 'User is not authorized' | ||
end | ||
end | ||
|
||
describe 'policy file creation' do | ||
before do | ||
@new_controller = 'Post' | ||
end | ||
|
||
after do | ||
Dir.chdir('test/testApp') do | ||
file = "lib/#{@application_name.downcase}/policies/#{@new_controller}Policy.rb" | ||
File.delete if file | ||
end | ||
end | ||
|
||
it 'generates policy' do | ||
Dir.chdir('test/testApp') do | ||
Commands.generate_policy(@application_name, @new_controller) | ||
generated_policy_string = "lib/#{@application_name.downcase}/policies/#{@new_controller}Policy.rb" | ||
assert File.file?("lib/#{@application_name.downcase}/policies/#{@new_controller}Policy.rb"), "The file lib/#{@application_name.downcase}/policies/#{@new_controller}Policy.rb is generated" | ||
assert File.readlines(generated_policy_string).grep(/authorized_roles_for_new/).size > 0, 'The file has content authorized_roles_for_new.' | ||
assert File.readlines(generated_policy_string).grep(/#{@application_name.downcase.capitalize}/).size > 0, "The file has content #{@application_name.downcase.capitalize}." | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.