wso2_toolbox 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +87 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bitbucket-pipelines.yml +19 -0
- data/lib/wso2_toolbox/identity_headers.rb +20 -0
- data/lib/wso2_toolbox/rspec_utils/shared_examples/identity_headers.rb +81 -0
- data/lib/wso2_toolbox/rspec_utils/shared_examples.rb +6 -0
- data/lib/wso2_toolbox/rspec_utils.rb +7 -0
- data/lib/wso2_toolbox/version.rb +3 -0
- data/lib/wso2_toolbox.rb +5 -0
- data/wso2_toolbox.gemspec +28 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4dd0daaf7f02586cdee53321e305ee6cb3ebf4de
|
4
|
+
data.tar.gz: fa5605e1bb1ef9466112214ba02bc83005062069
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6031fedca55bff5995e5f912d71fda9259f91b1826cd5a176c5fefb02f330aeb0aae1c32411fa76b708f194d2fc4bf66fa36282123c172bcfa033bcbda46c95
|
7
|
+
data.tar.gz: 3f2bbed00235ef592c8445b4e3f4d3d7b1c0c6b48499b3e788972778f4c71ebee902f0987637ea5b2c81017bac4921eb30c6ea77ce5be31cf2977df4a72f910a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
wso2_toolbox
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wso2_toolbox (0.1.0)
|
5
|
+
actionpack (>= 5.0)
|
6
|
+
activesupport (>= 5.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (5.1.4)
|
12
|
+
actionview (= 5.1.4)
|
13
|
+
activesupport (= 5.1.4)
|
14
|
+
rack (~> 2.0)
|
15
|
+
rack-test (>= 0.6.3)
|
16
|
+
rails-dom-testing (~> 2.0)
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
18
|
+
actionview (5.1.4)
|
19
|
+
activesupport (= 5.1.4)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
24
|
+
activesupport (5.1.4)
|
25
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
|
+
i18n (~> 0.7)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
tzinfo (~> 1.1)
|
29
|
+
builder (3.2.3)
|
30
|
+
concurrent-ruby (1.0.5)
|
31
|
+
crass (1.0.3)
|
32
|
+
diff-lcs (1.3)
|
33
|
+
erubi (1.7.0)
|
34
|
+
i18n (0.9.1)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
loofah (2.1.1)
|
37
|
+
crass (~> 1.0.2)
|
38
|
+
nokogiri (>= 1.5.9)
|
39
|
+
mini_portile2 (2.3.0)
|
40
|
+
minitest (5.10.3)
|
41
|
+
nokogiri (1.8.1)
|
42
|
+
mini_portile2 (~> 2.3.0)
|
43
|
+
rack (2.0.3)
|
44
|
+
rack-test (0.8.2)
|
45
|
+
rack (>= 1.0, < 3)
|
46
|
+
rails-controller-testing (1.0.2)
|
47
|
+
actionpack (~> 5.x, >= 5.0.1)
|
48
|
+
actionview (~> 5.x, >= 5.0.1)
|
49
|
+
activesupport (~> 5.x)
|
50
|
+
rails-dom-testing (2.0.3)
|
51
|
+
activesupport (>= 4.2.0)
|
52
|
+
nokogiri (>= 1.6)
|
53
|
+
rails-html-sanitizer (1.0.3)
|
54
|
+
loofah (~> 2.0)
|
55
|
+
rake (10.5.0)
|
56
|
+
rspec (3.7.0)
|
57
|
+
rspec-core (~> 3.7.0)
|
58
|
+
rspec-expectations (~> 3.7.0)
|
59
|
+
rspec-mocks (~> 3.7.0)
|
60
|
+
rspec-core (3.7.0)
|
61
|
+
rspec-support (~> 3.7.0)
|
62
|
+
rspec-expectations (3.7.0)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.7.0)
|
65
|
+
rspec-mocks (3.7.0)
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
+
rspec-support (~> 3.7.0)
|
68
|
+
rspec-support (3.7.0)
|
69
|
+
shoulda-matchers (3.1.2)
|
70
|
+
activesupport (>= 4.0.0)
|
71
|
+
thread_safe (0.3.6)
|
72
|
+
tzinfo (1.2.4)
|
73
|
+
thread_safe (~> 0.1)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
bundler (~> 1.16)
|
80
|
+
rails-controller-testing (~> 1.0)
|
81
|
+
rake (~> 10.0)
|
82
|
+
rspec (~> 3.0)
|
83
|
+
shoulda-matchers (~> 3.1)
|
84
|
+
wso2_toolbox!
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
1.16.0
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Wso2Toolbox
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wso2_toolbox`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'wso2_toolbox'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install wso2_toolbox
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Example controller
|
26
|
+
|
27
|
+
```
|
28
|
+
class MyController
|
29
|
+
include Wso2Toolbox::IdentityHeaders
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
### Example test
|
34
|
+
|
35
|
+
In `spec_helper.rb` require 'paper_trail/frameworks/rspec'.
|
36
|
+
|
37
|
+
```
|
38
|
+
require 'rails_helper'
|
39
|
+
|
40
|
+
RSpec.describe MyController do
|
41
|
+
it_behaves_like 'audit user', ApplicationController
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on Bitbucker at https://bitbucket.org/guideinvestimentos/wso2_toolboxÎ.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wso2_toolbox"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
image: ruby:2.4.1
|
2
|
+
|
3
|
+
pipelines:
|
4
|
+
default:
|
5
|
+
- step:
|
6
|
+
script:
|
7
|
+
- git archive --remote=git@bitbucket.org:guideinvestimentos/rails_defaults.git HEAD .rubocop.yml | tar -x
|
8
|
+
- bundle install
|
9
|
+
- gem install rubocop
|
10
|
+
- rspec -fdoc
|
11
|
+
- rubocop .
|
12
|
+
branches:
|
13
|
+
master:
|
14
|
+
- step:
|
15
|
+
script:
|
16
|
+
- gem build wso2_toolbox.gemspec
|
17
|
+
- curl -u $RUBYGEMS_USERNAME:$RUBYGEMS_PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
|
18
|
+
- chmod 0600 ~/.gem/credentials
|
19
|
+
- gem push $(ls *.gem)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module Wso2Toolbox
|
4
|
+
module IdentityHeaders
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_action :set_paper_trail_whodunnit
|
9
|
+
end
|
10
|
+
|
11
|
+
def user_identifier
|
12
|
+
user_header = request.headers[:HTTP_USER_IDENTIFIER]
|
13
|
+
user_header ? Base64.decode64(user_header) : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_for_paper_trail
|
17
|
+
user_identifier
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Wso2Toolbox
|
2
|
+
module RspecUtils
|
3
|
+
module SharedExamples
|
4
|
+
module IdentityHeaders
|
5
|
+
RSpec.shared_context 'stub identity headers' do |controller_class|
|
6
|
+
let(:user_hash) do
|
7
|
+
{
|
8
|
+
'id' => 1,
|
9
|
+
'user_name' => 'app-user',
|
10
|
+
'email' => 'noreplay@guideinvestimentos.com.br',
|
11
|
+
'remote_ip' => '127.0.0.1'
|
12
|
+
}
|
13
|
+
end
|
14
|
+
let(:base64_header) { Base64.strict_encode64(user_hash.to_s) }
|
15
|
+
let(:headers_hash) { { 'HTTP_USER_IDENTIFIER' => base64_header } }
|
16
|
+
let(:request_obj) do
|
17
|
+
instance_double('ActionDispatch::Request', headers: headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
allow_any_instance_of(controller_class).
|
22
|
+
to receive(:request) { request_obj }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.shared_examples 'set_paper_trail_whodunnit' do
|
27
|
+
describe 'before_action' do
|
28
|
+
it { is_expected.to use_before_action(:set_paper_trail_whodunnit) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.shared_examples 'get user identifier' do |controller_class|
|
33
|
+
include_context 'stub identity headers', controller_class
|
34
|
+
|
35
|
+
describe '#user_identifier' do
|
36
|
+
context 'receive user identifier header' do
|
37
|
+
let(:headers) do
|
38
|
+
ActionDispatch::Http::Headers.from_hash(headers_hash)
|
39
|
+
end
|
40
|
+
it { expect(subject.user_identifier).to eq user_hash.to_s }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'not receive user identifier header' do
|
44
|
+
let(:headers) { ActionDispatch::Http::Headers.from_hash({}) }
|
45
|
+
it { expect(subject.user_identifier).to be_nil }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
RSpec.shared_examples 'get user for paper_trail' do |controller_class|
|
51
|
+
include_context 'stub identity headers', controller_class
|
52
|
+
|
53
|
+
describe '#user_for_paper_trail' do
|
54
|
+
context 'receive user identifier header' do
|
55
|
+
before(:each) do
|
56
|
+
allow_any_instance_of(controller_class).
|
57
|
+
to receive(:user_identifier) { user_hash.to_s }
|
58
|
+
end
|
59
|
+
|
60
|
+
it { expect(subject.user_for_paper_trail).to eq user_hash.to_s }
|
61
|
+
end
|
62
|
+
context 'receive user identifier header' do
|
63
|
+
before(:each) do
|
64
|
+
allow_any_instance_of(controller_class).
|
65
|
+
to receive(:user_identifier) { nil }
|
66
|
+
end
|
67
|
+
|
68
|
+
it { expect(subject.user_for_paper_trail).to be_nil }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
RSpec.shared_examples 'audit user' do |controller_class|
|
74
|
+
it_behaves_like 'set_paper_trail_whodunnit'
|
75
|
+
it_behaves_like 'get user identifier', controller_class
|
76
|
+
it_behaves_like 'get user for paper_trail', controller_class
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/wso2_toolbox.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wso2_toolbox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wso2_toolbox'
|
8
|
+
spec.version = Wso2Toolbox::VERSION
|
9
|
+
spec.authors = ['Abner Carleto']
|
10
|
+
spec.email = ['abner.carleto@cedrotech.com']
|
11
|
+
|
12
|
+
spec.summary = 'WSO2 useful tools'
|
13
|
+
spec.homepage = 'https://bitbucket.org/guideinvestimentos/wso2_toolbox'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'actionpack', '>= 5.0'
|
21
|
+
spec.add_dependency 'activesupport', '>= 5.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rails-controller-testing', '~> 1.0'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wso2_toolbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abner Carleto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails-controller-testing
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: shoulda-matchers
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.1'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- abner.carleto@cedrotech.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".ruby-gemset"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- bitbucket-pipelines.yml
|
129
|
+
- lib/wso2_toolbox.rb
|
130
|
+
- lib/wso2_toolbox/identity_headers.rb
|
131
|
+
- lib/wso2_toolbox/rspec_utils.rb
|
132
|
+
- lib/wso2_toolbox/rspec_utils/shared_examples.rb
|
133
|
+
- lib/wso2_toolbox/rspec_utils/shared_examples/identity_headers.rb
|
134
|
+
- lib/wso2_toolbox/version.rb
|
135
|
+
- wso2_toolbox.gemspec
|
136
|
+
homepage: https://bitbucket.org/guideinvestimentos/wso2_toolbox
|
137
|
+
licenses: []
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.6.10
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: WSO2 useful tools
|
159
|
+
test_files: []
|