rserve-client 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/History.txt +4 -0
- data/Manifest.txt +1 -0
- data/README.md +0 -1
- data/data/Rserv-cryptonly.conf.example +4 -0
- data/data/Rserv-plaintext.conf.example +4 -0
- data/data/Rserv.passwords +1 -0
- data/lib/rserve.rb +15 -14
- data/lib/rserve/connection.rb +23 -15
- data/lib/rserve/packet.rb +1 -0
- data/lib/rserve/protocol.rb +1 -1
- data/lib/rserve/rexp.rb +19 -19
- data/spec/rserve_connection_authentication_spec.rb +70 -0
- data/spec/rserve_connection_on_unix_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fff9789e59308f0fc962b2d3a4fece6fdcc00b74
|
4
|
+
data.tar.gz: 5adc4082d943001c3fcb2cc9af70caf9afa00ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 459d3aae846e86289edf748ea0a74694e06fc77fe097bbb5639a5f338922408607418ab4006e220231480af0a9b23f00b9811d5c989632eae5bbb3be72c70e77
|
7
|
+
data.tar.gz: 97a53fdc28bc498980d30ca0935c00a5dc9877ddeb8c824221015eed6a7025712c61d9bd824fbf2ffd6c0388b3d91b81607ff1fa2b9de6600feaa75e33062972
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -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.
|
33
|
+
1.15.1
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -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
@@ -0,0 +1 @@
|
|
1
|
+
test password
|
data/lib/rserve.rb
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
require 'socket'
|
2
2
|
require 'rbconfig'
|
3
3
|
module Rserve
|
4
|
-
VERSION = '0.3.
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
|
data/lib/rserve/connection.rb
CHANGED
@@ -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
|
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+]
|
49
|
-
# [+:proc_rserve_ok+]
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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?
|
data/lib/rserve/packet.rb
CHANGED
data/lib/rserve/protocol.rb
CHANGED
data/lib/rserve/rexp.rb
CHANGED
@@ -424,32 +424,32 @@ module Rserve
|
|
424
424
|
end
|
425
425
|
|
426
426
|
|
427
|
-
|
428
|
-
|
429
|
-
|
427
|
+
require_relative 'rexp/environment'
|
428
|
+
require_relative 'rexp/null'
|
429
|
+
require_relative 'rexp/unknown'
|
430
430
|
|
431
431
|
|
432
|
-
|
432
|
+
require_relative 'rexp/vector'
|
433
433
|
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
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
|
-
|
441
|
+
require_relative 'rexp/factor'
|
442
442
|
|
443
|
-
|
444
|
-
|
443
|
+
require_relative 'rexp/genericvector'
|
444
|
+
require_relative 'rexp/expressionvector'
|
445
445
|
|
446
446
|
|
447
|
-
|
448
|
-
|
449
|
-
|
447
|
+
require_relative 'rexp/list'
|
448
|
+
require_relative 'rexp/language'
|
449
|
+
require_relative 'rexp/s4'
|
450
450
|
|
451
|
-
|
451
|
+
require_relative 'rexp/reference'
|
452
452
|
|
453
|
-
|
454
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
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.
|
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-
|
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
|