rserve-client 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c3a03347161784ff8220b9e7a8ef33620643fa5
4
- data.tar.gz: 46b6892b3f439202a362f3c1db6f9f75c26eb828
3
+ metadata.gz: fff9789e59308f0fc962b2d3a4fece6fdcc00b74
4
+ data.tar.gz: 5adc4082d943001c3fcb2cc9af70caf9afa00ef8
5
5
  SHA512:
6
- metadata.gz: 884b4e27bd68a01679bf774f21ee5f4b022ca591fef8f27cd1058ed27259da612cd6632e3206a570274399af195f137ec837c0ab5040535e895416ab688417f1
7
- data.tar.gz: 0909cebb7571cadda549e0c5965a01e58b4e1a46d3b48e750653a347b158afa8c483440ccc40c557fb8d5d96c3a3451ec440722a4e3699d02affc20be0713cd6
6
+ metadata.gz: 459d3aae846e86289edf748ea0a74694e06fc77fe097bbb5639a5f338922408607418ab4006e220231480af0a9b23f00b9811d5c989632eae5bbb3be72c70e77
7
+ data.tar.gz: 97a53fdc28bc498980d30ca0935c00a5dc9877ddeb8c824221015eed6a7025712c61d9bd824fbf2ffd6c0388b3d91b81607ff1fa2b9de6600feaa75e33062972
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
  gem 'hoe'
3
3
  gem 'rspec'
4
4
  gem 'rake'
5
+ gem 'rbx-require-relative', :platforms => :ruby_18
@@ -5,6 +5,7 @@ GEM
5
5
  hoe (3.16.0)
6
6
  rake (>= 0.8, < 13.0)
7
7
  rake (12.0.0)
8
+ rbx-require-relative (0.0.9)
8
9
  rspec (3.6.0)
9
10
  rspec-core (~> 3.6.0)
10
11
  rspec-expectations (~> 3.6.0)
@@ -25,7 +26,8 @@ PLATFORMS
25
26
  DEPENDENCIES
26
27
  hoe
27
28
  rake
29
+ rbx-require-relative
28
30
  rspec
29
31
 
30
32
  BUNDLED WITH
31
- 1.14.6
33
+ 1.15.1
@@ -1,3 +1,7 @@
1
+ === 0.3.3 / 2017-07-06
2
+
3
+ * Added support for crypt and plaintext authentication
4
+
1
5
  === 0.3.2 / 2017-05-17
2
6
 
3
7
  * Updated Gemfile
@@ -50,6 +50,7 @@ lib/rserve/withattributes.rb
50
50
  lib/rserve/withnames.rb
51
51
  spec/rserve_bug_1_spec.rb
52
52
  spec/rserve_bug_26_spec.rb
53
+ spec/rserve_connection_authentication_spec.rb
53
54
  spec/rserve_connection_on_unix_spec.rb
54
55
  spec/rserve_connection_spec.rb
55
56
  spec/rserve_double_spec.rb
data/README.md CHANGED
@@ -59,7 +59,6 @@ Cons:
59
59
 
60
60
  Implements
61
61
 
62
- * Authentification
63
62
  * Original test
64
63
 
65
64
  Spec
@@ -0,0 +1,4 @@
1
+ port 6313
2
+ auth required
3
+ plaintext disable
4
+ remote enable
@@ -0,0 +1,4 @@
1
+ port 6312
2
+ auth required
3
+ plaintext enable
4
+ remote enable
@@ -0,0 +1 @@
1
+ test password
@@ -1,26 +1,27 @@
1
1
  require 'socket'
2
2
  require 'rbconfig'
3
3
  module Rserve
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  ON_WINDOWS=RbConfig::CONFIG['arch']=~/mswin|mingw/
6
6
  end
7
7
 
8
8
  require 'spoon' if RUBY_PLATFORM == "java"
9
+ require 'require_relative' if RUBY_VERSION < "1.9"
9
10
 
10
- require 'rserve/withnames'
11
- require 'rserve/withattributes'
12
- require 'rserve/with2dnames'
13
- require 'rserve/with2dsizes'
11
+ require_relative 'rserve/withnames'
12
+ require_relative 'rserve/withattributes'
13
+ require_relative 'rserve/with2dnames'
14
+ require_relative 'rserve/with2dsizes'
14
15
 
15
16
 
16
- require 'rserve/protocol'
17
- require 'rserve/packet'
18
- require 'rserve/talk'
19
- require 'rserve/rexp'
20
- require 'rserve/engine'
21
- require 'rserve/session'
22
- require 'rserve/connection'
23
- require 'rserve/rlist'
24
- require 'rserve/rfactor'
17
+ require_relative 'rserve/protocol'
18
+ require_relative 'rserve/packet'
19
+ require_relative 'rserve/talk'
20
+ require_relative 'rserve/rexp'
21
+ require_relative 'rserve/engine'
22
+ require_relative 'rserve/session'
23
+ require_relative 'rserve/connection'
24
+ require_relative 'rserve/rlist'
25
+ require_relative 'rserve/rfactor'
25
26
 
26
27
 
@@ -10,6 +10,7 @@ module Rserve
10
10
  IncorrectServerError=Class.new(StandardError)
11
11
  IncorrectServerVersionError=Class.new(StandardError)
12
12
  IncorrectProtocolError=Class.new(StandardError)
13
+ IncorrectCredentialsError=Class.new(StandardError)
13
14
  NotConnectedError=Class.new(StandardError)
14
15
  # Eval error
15
16
  class EvalError < RuntimeError
@@ -41,12 +42,14 @@ module Rserve
41
42
  # You could provide a hash with options. Options are analog to java client:
42
43
  # [+:auth_req+] If authentification is required (false by default)
43
44
  # [+:transfer_charset+] Transfer charset ("UTF-8" by default)
44
- # [+:auth_type+] Type of authentification (AT_plain by default)
45
+ # [+:auth_type+] Type of authentication (AT_plain by default)
45
46
  # [+:hostname+] Hostname of Rserve ("127.0.0.1" by default)
46
47
  # [+:port_number+] Port Number of Rserve (6311 by default)
47
48
  # [+:max_tries+] Maximum number of tries before give up (5 by default)
48
- # [+:cmd_init+] Command to init Rserve if not initialized ("R CMD Rserve" by default)
49
- # [+:proc_rserve_ok+] Proc testing if Rserve works (uses system by default)
49
+ # [+:cmd_init+] Command to init Rserve if not initialized ("R CMD Rserve" by default)
50
+ # [+:proc_rserve_ok+] Proc testing if Rserve works (uses system by default)
51
+ # [+:username+] Username to use (if authentication is required)
52
+ # [+:password+] Password to use (if authentication is required)
50
53
  def initialize(opts=Hash.new)
51
54
  @auth_req = opts.delete(:auth_req) || false
52
55
  @transfer_charset = opts.delete(:transfer_charset) || "UTF-8"
@@ -56,6 +59,8 @@ module Rserve
56
59
  @max_tries = opts.delete(:max_tries) || 5
57
60
  @cmd_init = opts.delete(:cmd_init) || "R CMD Rserve"
58
61
  @proc_rserve_ok = opts.delete(:proc_rserve_ok) || lambda { system "killall -s 0 Rserve" }
62
+ @username = opts.delete(:username) || nil
63
+ @password = opts.delete(:password) || nil
59
64
  @session = opts.delete(:session) || nil
60
65
  @tries = 0
61
66
  @connected=false
@@ -115,20 +120,15 @@ module Rserve
115
120
  (3..7).each do |i|
116
121
  attr=input[i]
117
122
  if (attr=="ARpt")
118
- if (!auth_req) # this method is only fallback when no other was specified
119
- auth_req=true
120
- auth_type=AT_plain
121
- end
122
- end
123
- if (attr=="ARuc")
124
- auth_req=true
125
- authType=AT_crypt
126
- end
127
- if (attr[0]=='K')
128
- key=attr[1,3]
123
+ @auth_req=true
124
+ elsif (attr=="ARuc")
125
+ @auth_req=true
126
+ @auth_type=AT_crypt #
127
+ elsif (attr[0..0]=='K')
128
+ @key=attr[1,2]
129
129
  end
130
-
131
130
  end
131
+ login if auth_req
132
132
  else # we have a session to take care of
133
133
  @s.write(@session.key.pack("C*"))
134
134
  @rsrv_version=session.rsrv_version
@@ -143,6 +143,14 @@ module Rserve
143
143
  @connected
144
144
  end
145
145
 
146
+ # This server requires a login. Send the required credentials to the server.
147
+ def login
148
+ raise IncorrectCredentialsError, "Need username and password to connect" if @username.nil? || @password.nil?
149
+ @password = @password.crypt(key) if key && auth_type == AT_crypt
150
+ rp = @rt.request({:cmd => Rserve::Protocol::CMD_login, :cont => "#{@username}\n#{@password}"})
151
+ raise IncorrectCredentialsError, "Server did not accept credentials" if rp.error?
152
+ end
153
+
146
154
  # Closes current connection
147
155
  def close
148
156
  if !@s.nil? and !@s.closed?
@@ -6,6 +6,7 @@ module Rserve
6
6
  ERROR_DESCRIPTIONS={
7
7
  2=>'Invalid expression',
8
8
  3=>'Parse error',
9
+ 65=>'Login error',
9
10
  127=>'Unknown variable/method'}
10
11
 
11
12
  def initialize(cmd, cont)
@@ -230,4 +230,4 @@ module Rserve
230
230
  end
231
231
  end
232
232
 
233
- require 'rserve/protocol/rexpfactory'
233
+ require_relative 'protocol/rexpfactory'
@@ -424,32 +424,32 @@ module Rserve
424
424
  end
425
425
 
426
426
 
427
- require 'rserve/rexp/environment'
428
- require 'rserve/rexp/null'
429
- require 'rserve/rexp/unknown'
427
+ require_relative 'rexp/environment'
428
+ require_relative 'rexp/null'
429
+ require_relative 'rexp/unknown'
430
430
 
431
431
 
432
- require 'rserve/rexp/vector'
432
+ require_relative 'rexp/vector'
433
433
 
434
- require 'rserve/rexp/raw'
435
- require 'rserve/rexp/symbol'
436
- require 'rserve/rexp/string'
437
- require 'rserve/rexp/double'
438
- require 'rserve/rexp/integer'
439
- require 'rserve/rexp/logical'
434
+ require_relative 'rexp/raw'
435
+ require_relative 'rexp/symbol'
436
+ require_relative 'rexp/string'
437
+ require_relative 'rexp/double'
438
+ require_relative 'rexp/integer'
439
+ require_relative 'rexp/logical'
440
440
 
441
- require 'rserve/rexp/factor'
441
+ require_relative 'rexp/factor'
442
442
 
443
- require 'rserve/rexp/genericvector'
444
- require 'rserve/rexp/expressionvector'
443
+ require_relative 'rexp/genericvector'
444
+ require_relative 'rexp/expressionvector'
445
445
 
446
446
 
447
- require 'rserve/rexp/list'
448
- require 'rserve/rexp/language'
449
- require 'rserve/rexp/s4'
447
+ require_relative 'rexp/list'
448
+ require_relative 'rexp/language'
449
+ require_relative 'rexp/s4'
450
450
 
451
- require 'rserve/rexp/reference'
451
+ require_relative 'rexp/reference'
452
452
 
453
- require 'rserve/rexp/wrapper'
454
- require 'rserve/rexp/function'
453
+ require_relative 'rexp/wrapper'
454
+ require_relative 'rexp/function'
455
455
 
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
+ require 'tempfile'
3
+
4
+ describe Rserve::Connection do
5
+ before(:all) do
6
+ lambda { system "killall Rserve" }.call #clean up any extra Rserves
7
+ password_file = File.expand_path("./data/Rserv.passwords")
8
+
9
+ plain_config = IO.read('./data/Rserv-plaintext.conf.example')
10
+ plain_config = plain_config + "\npwdfile #{password_file}\n"
11
+ @plain_config_file = Tempfile.new('Rserv-plaintext.conf')
12
+ @plain_config_file.write(plain_config)
13
+ @plain_config_file.flush
14
+ crypt_config = IO.read('./data/Rserv-cryptonly.conf.example')
15
+ crypt_config = crypt_config + "\npwdfile #{password_file}\n"
16
+ @crypt_config_file = Tempfile.new('Rserv-cryptonly.conf')
17
+ @crypt_config_file.write(crypt_config)
18
+ @crypt_config_file.flush
19
+ end
20
+ describe "opening and closing plaintext" do
21
+ before(:all) do
22
+ @r=Rserve::Connection.new(:cmd_init => "R CMD Rserve --RS-conf #{@plain_config_file.path}", :username => "test", :password => "password", :port_number => 6312)
23
+ end
24
+ it "should be open a connection and receive ID-String" do
25
+ @r.get_server_version.should==103
26
+ @r.protocol.should=="QAP1"
27
+ @r.last_error.should=="OK"
28
+ @r.rt.should be_instance_of(Rserve::Talk)
29
+ end
30
+ it "should eval something properly" do
31
+ @r.void_eval("x<-1").should be true
32
+ end
33
+ it "should shut down correctly" do
34
+ @r.should be_connected
35
+ @r.close.should be true
36
+ @r.should_not be_connected
37
+ end
38
+ end
39
+ describe "opening and closing plaintext wrong password" do
40
+ it "should fail to connect" do
41
+ expect {@r=Rserve::Connection.new(:cmd_init => "R CMD Rserve --RS-conf #{@plain_config_file.path}", :username => "test", :password => "wrongpassword", :port_number => 6312)}.to raise_error(Rserve::Connection::IncorrectCredentialsError)
42
+ lambda { system "killall Rserve" }.call #clean up any extra Rserves
43
+ end
44
+ end
45
+ describe "opening and closing crypt" do
46
+ before(:all) do
47
+ @r=Rserve::Connection.new(:cmd_init => "R CMD Rserve --RS-conf #{@crypt_config_file.path}", :username => "test", :password => "password", :port_number => 6313)
48
+ end
49
+ it "should be open a connection and receive ID-String" do
50
+ @r.get_server_version.should==103
51
+ @r.protocol.should=="QAP1"
52
+ @r.last_error.should=="OK"
53
+ @r.rt.should be_instance_of(Rserve::Talk)
54
+ end
55
+ it "should eval something properly" do
56
+ @r.void_eval("x<-1").should be true
57
+ end
58
+ it "should shut down correctly" do
59
+ @r.should be_connected
60
+ @r.close.should be true
61
+ @r.should_not be_connected
62
+ end
63
+ end
64
+ describe "opening and closing crypt wrong password" do
65
+ it "should fail to connect" do
66
+ expect {@r=Rserve::Connection.new(:cmd_init => "R CMD Rserve --RS-conf #{@crypt_config_file.path}", :username => "test", :password => "wrongpassword", :port_number => 6313)}.to raise_error(Rserve::Connection::IncorrectCredentialsError)
67
+ lambda { system "killall Rserve" }.call #clean up any extra Rserves
68
+ end
69
+ end
70
+ end
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
2
  describe "Rserve::Connection on unix" do
3
3
  if !Rserve::ON_WINDOWS
4
4
  before do
5
- @r=Rserve::Connection.new
5
+ @r=Rserve::Connection.new
6
6
  end
7
7
  after do
8
8
  @r.close if @r.connected?
@@ -4,6 +4,7 @@ require 'rserve'
4
4
  require 'matrix'
5
5
  require 'pp'
6
6
 
7
+ INFINITY = +1.0/0.0 if RUBY_VERSION < "1.9"
7
8
 
8
9
  RSpec.configure do |config|
9
10
  config.expect_with :rspec do |c|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rserve-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bustos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,6 +59,9 @@ files:
59
59
  - benchmark/comparison_2010_06_07.xls
60
60
  - benchmark/comparison_2010_06_07_using_pack.xls
61
61
  - benchmark/plot.rb
62
+ - data/Rserv-cryptonly.conf.example
63
+ - data/Rserv-plaintext.conf.example
64
+ - data/Rserv.passwords
62
65
  - data/gettysburg.txt
63
66
  - examples/gettysburg.rb
64
67
  - examples/hello_world.rb
@@ -101,6 +104,7 @@ files:
101
104
  - rserve-client.gemspec
102
105
  - spec/rserve_bug_1_spec.rb
103
106
  - spec/rserve_bug_26_spec.rb
107
+ - spec/rserve_connection_authentication_spec.rb
104
108
  - spec/rserve_connection_on_unix_spec.rb
105
109
  - spec/rserve_connection_spec.rb
106
110
  - spec/rserve_double_spec.rb