racf 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +18 -0
  4. data/Gemfile +14 -0
  5. data/Gemfile.lock +40 -0
  6. data/README.rdoc +56 -0
  7. data/Rakefile +9 -0
  8. data/TODO.txt +5 -0
  9. data/config/racf.yml.sample +27 -0
  10. data/lib/racf.rb +78 -0
  11. data/lib/racf/client.rb +138 -0
  12. data/lib/racf/commands/abstract_command.rb +13 -0
  13. data/lib/racf/commands/listgrp.rb +189 -0
  14. data/lib/racf/commands/listgrp/group_members_parser.rb +104 -0
  15. data/lib/racf/commands/listuser.rb +112 -0
  16. data/lib/racf/commands/rlist.rb +208 -0
  17. data/lib/racf/commands/search.rb +31 -0
  18. data/lib/racf/pagers/cached_ispf_pager.rb +91 -0
  19. data/lib/racf/pagers/ispf_pager.rb +57 -0
  20. data/lib/racf/s3270.rb +136 -0
  21. data/lib/racf/session.rb +149 -0
  22. data/lib/racf/version.rb +3 -0
  23. data/racf.gemspec +16 -0
  24. data/script/ci +3 -0
  25. data/spec/fixtures/config/racf.yml +9 -0
  26. data/spec/fixtures/listgrp/multiple_groups_multiple_members.txt +26 -0
  27. data/spec/fixtures/listgrp/multiple_members.txt +10 -0
  28. data/spec/fixtures/listgrp/no_members.txt +4 -0
  29. data/spec/fixtures/listgrp/not_found_groups.txt +21 -0
  30. data/spec/fixtures/listgrp/one_group.txt +7 -0
  31. data/spec/fixtures/listgrp/one_group_with_members.txt +13 -0
  32. data/spec/fixtures/listgrp/one_member.txt +7 -0
  33. data/spec/fixtures/listuser/all_users.txt +45 -0
  34. data/spec/fixtures/listuser/just_users_not_found.txt +3 -0
  35. data/spec/fixtures/listuser/one_user.txt +47 -0
  36. data/spec/fixtures/listuser/some_not_found_users.txt +88 -0
  37. data/spec/fixtures/racf_cache_dump.yml +9 -0
  38. data/spec/fixtures/rlist/gims.txt +135 -0
  39. data/spec/fixtures/rlist/gims_with_no_tims.txt +135 -0
  40. data/spec/fixtures/rlist/gims_with_not_found.txt +89 -0
  41. data/spec/fixtures/rlist/just_one_not_found.txt +1 -0
  42. data/spec/fixtures/rlist/multiple_not_found.txt +3 -0
  43. data/spec/fixtures/rlist/rlist_success.txt +50 -0
  44. data/spec/fixtures/rlist/tims_without_users.txt +119 -0
  45. data/spec/fixtures/search/gims.txt +30 -0
  46. data/spec/fixtures/search/tims.txt +30 -0
  47. data/spec/fixtures/session/screen_with_bottom_menu.txt +31 -0
  48. data/spec/fixtures/session/screen_with_top_and_bottom_menu.txt +47 -0
  49. data/spec/fixtures/session/screen_with_top_menu.txt +29 -0
  50. data/spec/fixtures/session/screen_without_menu.txt +13 -0
  51. data/spec/racf/client_spec.rb +155 -0
  52. data/spec/racf/commands/listgrp/group_members_parser_spec.rb +82 -0
  53. data/spec/racf/commands/listgrp_spec.rb +303 -0
  54. data/spec/racf/commands/listuser_spec.rb +123 -0
  55. data/spec/racf/commands/rlist_spec.rb +257 -0
  56. data/spec/racf/commands/search_spec.rb +66 -0
  57. data/spec/racf/pagers/cached_ispf_pager_spec.rb +212 -0
  58. data/spec/racf/pagers/ispf_pager_spec.rb +59 -0
  59. data/spec/racf/session_spec.rb +114 -0
  60. data/spec/racf_spec.rb +106 -0
  61. data/spec/spec_helper.rb +18 -0
  62. data/spec/support/helpers.rb +5 -0
  63. metadata +162 -0
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ require 'racf/pagers/ispf_pager'
4
+
5
+ describe Racf::Pagers::IspfPager do
6
+ before(:each) do
7
+ Racf.logger = double.as_null_object
8
+ end
9
+
10
+ describe "#run" do
11
+ context "argument is an Array" do
12
+ it "runs the command limiting the number of items" do
13
+ total_items = (1...40).map { |i| "ITEM#{i}" }
14
+
15
+ command = double("command")
16
+ command.
17
+ should_receive(:extract_resources).
18
+ with([total_items]).
19
+ and_return(total_items)
20
+
21
+ command.
22
+ should_receive(:run).
23
+ with(total_items[0..19]).
24
+ and_return({:a => :ok})
25
+
26
+ command.
27
+ should_receive(:run).
28
+ with(total_items[20..40]).
29
+ and_return({:b => :ok})
30
+
31
+ pager = described_class.new(command)
32
+
33
+ results = pager.run(total_items)
34
+ results[:a].should be(:ok)
35
+ results[:b].should be(:ok)
36
+ end
37
+ end
38
+
39
+ context "argument is a String" do
40
+ it "runs through, without pagination" do
41
+ command = double("command")
42
+
43
+ command.
44
+ should_receive(:extract_resources).
45
+ with(['TEST']).
46
+ and_return(['TEST'])
47
+
48
+ command.
49
+ should_receive(:run).
50
+ with(['TEST']).
51
+ and_return({})
52
+
53
+ pager = described_class.new(command)
54
+
55
+ pager.run('TEST')
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+ require 'racf/session'
3
+
4
+ describe Racf::Session do
5
+ describe "#start" do
6
+ let(:scraper) { mock("scraper") }
7
+
8
+ before(:each) do
9
+ scraper.should_receive(:complete_screen).and_return("Enter LOGON parameters below")
10
+ scraper.should_receive(:string_action).with("TA")
11
+ scraper.should_receive(:string_action).with("user_id")
12
+ scraper.should_receive(:string_action).with("password")
13
+ scraper.should_receive(:action).with("enter")
14
+ scraper.should_receive(:string_action).with("logoff")
15
+ scraper.should_receive(:close)
16
+ end
17
+
18
+ context "when user is already logged in" do
19
+ it "raises an error" do
20
+ scraper.should_receive(:screen).and_return("LOGON rejected, UserId user_id already logged on")
21
+
22
+ session = Racf::Session.new({
23
+ :scraper => scraper,
24
+ :user_id => 'user_id',
25
+ :password => 'password'
26
+ })
27
+
28
+ # Since mock methods are injected into Object, we can
29
+ # play with the scope lookup of the method and mock it
30
+ # in order to make tests faster.
31
+ session.should_receive(:sleep).with(2)
32
+
33
+ expect {
34
+ session.start
35
+ }.to raise_error(Racf::LoginError, "User user_id already logged in")
36
+ end
37
+ end
38
+
39
+ context "when user has expired password" do
40
+ it "raises an error" do
41
+ scraper.
42
+ should_receive(:screen).
43
+ twice.
44
+ and_return("CURRENT PASSWORD HAS EXPIRED - PLEASE ENTER NEW PASSWORD")
45
+
46
+ session = Racf::Session.new({
47
+ :scraper => scraper,
48
+ :user_id => 'user_id',
49
+ :password => 'password'
50
+ })
51
+
52
+ # Since mock methods are injected into Object, we can
53
+ # play with the scope lookup of the method and mock it
54
+ # in order to make tests faster.
55
+ session.should_receive(:sleep).with(2)
56
+
57
+ expect {
58
+ session.start
59
+ }.to raise_error(Racf::LoginError, "Password for user user_id has expired")
60
+ end
61
+ end
62
+
63
+ context "when password not authorized" do
64
+ it "raises an error" do
65
+ scraper.stub(:screen).and_return("PASSWORD NOT AUTHORIZED FOR USERID")
66
+
67
+ session = Racf::Session.new({
68
+ :scraper => scraper,
69
+ :user_id => 'user_id',
70
+ :password => 'password'
71
+ })
72
+
73
+ # Since mock methods are injected into Object, we can
74
+ # play with the scope lookup of the method and mock it
75
+ # in order to make tests faster.
76
+ session.should_receive(:sleep).with(2)
77
+
78
+ expect {
79
+ session.start
80
+ }.to raise_error(Racf::LoginError, "Password for user user_id is not authorized")
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#remove_ispf_menu" do
86
+ before do
87
+ @session = Racf::Session.new( :scraper => double("dummy scrapper") )
88
+ end
89
+
90
+ context "when there's a ISPF menu at the top" do
91
+ it "removes the menu" do
92
+ screen_with_top_menu = read_fixture("session/screen_with_top_menu.txt")
93
+ screen = @session.remove_ispf_menu(screen_with_top_menu)
94
+ screen.should == read_fixture("session/screen_without_menu.txt")
95
+ end
96
+ end
97
+
98
+ context "when there's a ISPF menu at the bottom" do
99
+ it "removes the menu" do
100
+ screen_with_bottom_menu = read_fixture("session/screen_with_bottom_menu.txt")
101
+ screen = @session.remove_ispf_menu(screen_with_bottom_menu)
102
+ screen.should == read_fixture("session/screen_without_menu.txt")
103
+ end
104
+ end
105
+
106
+ context "when there's a ISPF menu at top and at the bottom" do
107
+ it "removes the menu" do
108
+ screen_with_top_and_bottom_menu = read_fixture("session/screen_with_top_and_bottom_menu.txt")
109
+ screen = @session.remove_ispf_menu(screen_with_top_and_bottom_menu)
110
+ screen.should == read_fixture("session/screen_without_menu.txt")
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Racf do
4
+ subject { Racf }
5
+
6
+ it { should respond_to :config_file_path=, :env=, :config=, :dump_file_path= }
7
+
8
+ it "defaults config file to config/racf.yml" do
9
+ Racf.config_file_path.to_s.should =~ /config\/racf.yml$/
10
+ end
11
+
12
+ it "defaults dump cache file to tmp/racf_cache_dump.yml" do
13
+ Racf.config[:dump_file] = nil
14
+ # TODO Improve the line below
15
+ # I know that using instance_variable_set to make a test green is so fucked
16
+ # up. What we need to do is probably not saving the dump_file_path
17
+ # as instance variable of the module Racf.
18
+ Racf.instance_variable_set(:@dump_file_path, nil)
19
+ Racf.dump_file_path.to_s.should =~ /tmp\/racf_cache_dump.yml$/
20
+ end
21
+
22
+ context "logging" do
23
+ # TODO: review this. Since we use Racf.logger, it is globally setted for the entire spec
24
+ # if run this randomly it might affect specs.
25
+ #
26
+ # This does not stays defined here, if will be used, it might be interesting to set it
27
+ # before all specs
28
+ class SpyLogger
29
+ attr_reader :logs
30
+
31
+ def initialize
32
+ @logs = []
33
+ end
34
+
35
+ def info(message)
36
+ @logs << message
37
+ end
38
+
39
+ def warn(message)
40
+ # created to stub in client spec
41
+ end
42
+ end
43
+
44
+ it "can be given a custom logger" do
45
+ logger = SpyLogger.new
46
+ Racf.logger = logger
47
+
48
+ Racf.logger.info("logging something")
49
+
50
+ logger.logs.should have(1).logging
51
+ logger.logs[0].should == "logging something"
52
+ end
53
+ end
54
+
55
+ describe ".root" do
56
+ subject { Racf.root }
57
+ it { should be_instance_of Pathname }
58
+ end
59
+
60
+ describe ".env" do
61
+ before { Racf.env = nil }
62
+ subject { Racf.env }
63
+
64
+ it { should == "development" }
65
+
66
+ it "can be set" do
67
+ expect {
68
+ Racf.env = "dev"
69
+ }.to change(Racf, :env).to("dev")
70
+ end
71
+
72
+ context "RAILS_ENV" do
73
+ before { ENV['RAILS_ENV'] = "qa" }
74
+ it { should == "qa" }
75
+ after { ENV.delete('RAILS_ENV') }
76
+ end
77
+
78
+ context "RACF_ENV" do
79
+ before { ENV['RACF_ENV'] = "production" }
80
+ it { should == "production" }
81
+ after { ENV.delete('RACF_ENV') }
82
+ end
83
+ end
84
+
85
+ describe ".config" do
86
+ before { Racf.config = nil }
87
+
88
+ it "returns empty hash if not found config for environment" do
89
+ Racf.env = "development"
90
+ Racf.config.should == {}
91
+ end
92
+
93
+ it "reads config file" do
94
+ Racf.env = "test"
95
+ Racf.config.should include(
96
+ :user_id => "test",
97
+ :password => "secret",
98
+ :server_address => "127.0.0.1",
99
+ :server_port => 3270,
100
+ :script_port => 3003,
101
+ :caching => false,
102
+ :dump_file => "cache_dump.yml"
103
+ )
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+
4
+ Bundler.setup(:test)
5
+
6
+ require "rspec"
7
+
8
+ require 'racf'
9
+
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file_path| require file_path }
11
+
12
+ # Use fixture config file for tests
13
+ Racf.env = "test"
14
+ Racf.config_file_path = Racf.root.join("spec", "fixtures", "config", "racf.yml")
15
+
16
+ RSpec.configure do |config|
17
+ config.include Helpers
18
+ end
@@ -0,0 +1,5 @@
1
+ module Helpers
2
+ def read_fixture(fixture_name)
3
+ File.read("spec/fixtures/#{fixture_name}")
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: racf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hugo Barauna
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: state_machine
16
+ requirement: &2154162000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2154162000
25
+ description:
26
+ email:
27
+ - hugo.barauna@autoseg.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - .rspec
34
+ - .travis.yml
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - README.rdoc
38
+ - Rakefile
39
+ - TODO.txt
40
+ - config/racf.yml.sample
41
+ - lib/racf.rb
42
+ - lib/racf/client.rb
43
+ - lib/racf/commands/abstract_command.rb
44
+ - lib/racf/commands/listgrp.rb
45
+ - lib/racf/commands/listgrp/group_members_parser.rb
46
+ - lib/racf/commands/listuser.rb
47
+ - lib/racf/commands/rlist.rb
48
+ - lib/racf/commands/search.rb
49
+ - lib/racf/pagers/cached_ispf_pager.rb
50
+ - lib/racf/pagers/ispf_pager.rb
51
+ - lib/racf/s3270.rb
52
+ - lib/racf/session.rb
53
+ - lib/racf/version.rb
54
+ - racf.gemspec
55
+ - script/ci
56
+ - spec/fixtures/config/racf.yml
57
+ - spec/fixtures/listgrp/multiple_groups_multiple_members.txt
58
+ - spec/fixtures/listgrp/multiple_members.txt
59
+ - spec/fixtures/listgrp/no_members.txt
60
+ - spec/fixtures/listgrp/not_found_groups.txt
61
+ - spec/fixtures/listgrp/one_group.txt
62
+ - spec/fixtures/listgrp/one_group_with_members.txt
63
+ - spec/fixtures/listgrp/one_member.txt
64
+ - spec/fixtures/listuser/all_users.txt
65
+ - spec/fixtures/listuser/just_users_not_found.txt
66
+ - spec/fixtures/listuser/one_user.txt
67
+ - spec/fixtures/listuser/some_not_found_users.txt
68
+ - spec/fixtures/racf_cache_dump.yml
69
+ - spec/fixtures/rlist/gims.txt
70
+ - spec/fixtures/rlist/gims_with_no_tims.txt
71
+ - spec/fixtures/rlist/gims_with_not_found.txt
72
+ - spec/fixtures/rlist/just_one_not_found.txt
73
+ - spec/fixtures/rlist/multiple_not_found.txt
74
+ - spec/fixtures/rlist/rlist_success.txt
75
+ - spec/fixtures/rlist/tims_without_users.txt
76
+ - spec/fixtures/search/gims.txt
77
+ - spec/fixtures/search/tims.txt
78
+ - spec/fixtures/session/screen_with_bottom_menu.txt
79
+ - spec/fixtures/session/screen_with_top_and_bottom_menu.txt
80
+ - spec/fixtures/session/screen_with_top_menu.txt
81
+ - spec/fixtures/session/screen_without_menu.txt
82
+ - spec/racf/client_spec.rb
83
+ - spec/racf/commands/listgrp/group_members_parser_spec.rb
84
+ - spec/racf/commands/listgrp_spec.rb
85
+ - spec/racf/commands/listuser_spec.rb
86
+ - spec/racf/commands/rlist_spec.rb
87
+ - spec/racf/commands/search_spec.rb
88
+ - spec/racf/pagers/cached_ispf_pager_spec.rb
89
+ - spec/racf/pagers/ispf_pager_spec.rb
90
+ - spec/racf/session_spec.rb
91
+ - spec/racf_spec.rb
92
+ - spec/spec_helper.rb
93
+ - spec/support/helpers.rb
94
+ homepage: ''
95
+ licenses: []
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ segments:
107
+ - 0
108
+ hash: 2045548294841115447
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ segments:
116
+ - 0
117
+ hash: 2045548294841115447
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.10
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: A wrapper around IBM's Resource Access Control Facility
124
+ test_files:
125
+ - spec/fixtures/config/racf.yml
126
+ - spec/fixtures/listgrp/multiple_groups_multiple_members.txt
127
+ - spec/fixtures/listgrp/multiple_members.txt
128
+ - spec/fixtures/listgrp/no_members.txt
129
+ - spec/fixtures/listgrp/not_found_groups.txt
130
+ - spec/fixtures/listgrp/one_group.txt
131
+ - spec/fixtures/listgrp/one_group_with_members.txt
132
+ - spec/fixtures/listgrp/one_member.txt
133
+ - spec/fixtures/listuser/all_users.txt
134
+ - spec/fixtures/listuser/just_users_not_found.txt
135
+ - spec/fixtures/listuser/one_user.txt
136
+ - spec/fixtures/listuser/some_not_found_users.txt
137
+ - spec/fixtures/racf_cache_dump.yml
138
+ - spec/fixtures/rlist/gims.txt
139
+ - spec/fixtures/rlist/gims_with_no_tims.txt
140
+ - spec/fixtures/rlist/gims_with_not_found.txt
141
+ - spec/fixtures/rlist/just_one_not_found.txt
142
+ - spec/fixtures/rlist/multiple_not_found.txt
143
+ - spec/fixtures/rlist/rlist_success.txt
144
+ - spec/fixtures/rlist/tims_without_users.txt
145
+ - spec/fixtures/search/gims.txt
146
+ - spec/fixtures/search/tims.txt
147
+ - spec/fixtures/session/screen_with_bottom_menu.txt
148
+ - spec/fixtures/session/screen_with_top_and_bottom_menu.txt
149
+ - spec/fixtures/session/screen_with_top_menu.txt
150
+ - spec/fixtures/session/screen_without_menu.txt
151
+ - spec/racf/client_spec.rb
152
+ - spec/racf/commands/listgrp/group_members_parser_spec.rb
153
+ - spec/racf/commands/listgrp_spec.rb
154
+ - spec/racf/commands/listuser_spec.rb
155
+ - spec/racf/commands/rlist_spec.rb
156
+ - spec/racf/commands/search_spec.rb
157
+ - spec/racf/pagers/cached_ispf_pager_spec.rb
158
+ - spec/racf/pagers/ispf_pager_spec.rb
159
+ - spec/racf/session_spec.rb
160
+ - spec/racf_spec.rb
161
+ - spec/spec_helper.rb
162
+ - spec/support/helpers.rb