rubyment 0.6.25510166 → 0.6.25520442
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 +4 -4
- data/lib/rubyment.rb +437 -63
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cce36ba8078584171153cda12ca7047f3d200432
|
4
|
+
data.tar.gz: d5a3ac0260a86b0777233502f000f2fa346a5538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ad63e004ceb35092d1bb56df6a7b4d832c94e6f164f759b4b8955ac345c43cdc4e59c644a7e6230c27618ae75f3e9dd6d460db0864380d440307d3fca013994
|
7
|
+
data.tar.gz: 483f0e5096aa5bbe5044e9e3968110e9f4472f6becc35aa036bd92f6b67782390a07938f948c782103839e89415969fc033ad0d11b56a670a510aa9f5cae0ad4
|
data/lib/rubyment.rb
CHANGED
@@ -140,21 +140,46 @@ class Rubyment
|
|
140
140
|
# @param [splat] +args+, an splat whose elements are expected to be +blea_args+ and +blocks_args+:
|
141
141
|
# +blea_args+:: [Array] args to be used internally, which are expected to be:
|
142
142
|
# +exception_admitted+:: [Boolean]
|
143
|
-
# +output_exception+:: [Boolean]
|
143
|
+
# +output_exception+:: [Boolean] note that this only makes sense if exception is admitted -- otherwise an exception will be normally thrown.
|
144
|
+
# +ret_nil_on_exception+:: [Boolean] enforces that +nil+ will be returned on exception
|
144
145
|
# +blocks_args+:: [splat] args to be forwarded to the block call
|
145
146
|
# @return [Proc]
|
146
147
|
def blea *args, &block
|
147
148
|
blea_args, *block_args = args
|
148
149
|
blea_args ||= blea_args.nne []
|
149
|
-
exception_admitted, output_exception = blea_args
|
150
|
-
exception_admitted
|
151
|
-
output_exception
|
152
|
-
|
150
|
+
exception_admitted, output_exception, ret_nil_on_exception = blea_args
|
151
|
+
exception_admitted = exception_admitted.nne
|
152
|
+
output_exception = output_exception.nne
|
153
|
+
bloe_method = ret_nil_on_exception && :bloef || :bloe
|
154
|
+
ble_method = output_exception && bloe_method || :blef
|
153
155
|
bl_to_call = exception_admitted && ble_method || :bl
|
154
156
|
send bl_to_call, *block_args, &block
|
155
157
|
end
|
156
158
|
|
157
159
|
|
160
|
+
# creates a Proc out of a block,
|
161
|
+
# will capture all exceptions
|
162
|
+
# inside that block and ignore it
|
163
|
+
# will return nil
|
164
|
+
def bloef *args, &block
|
165
|
+
block ||= lambda {}
|
166
|
+
bl {
|
167
|
+
begin
|
168
|
+
block.call *args
|
169
|
+
rescue => e
|
170
|
+
stderr = @memory[:stderr]
|
171
|
+
rv = [e.backtrace.join("\n"), e]
|
172
|
+
stderr.puts "#{__method__} exception backtrace:"
|
173
|
+
stderr.puts rv[0]
|
174
|
+
stderr.puts "#{__method__} exception inspection:"
|
175
|
+
stderr.puts rv[1].inspect
|
176
|
+
stderr.puts "#{__method__} exception message:"
|
177
|
+
stderr.puts rv[1]
|
178
|
+
end
|
179
|
+
}
|
180
|
+
end
|
181
|
+
|
182
|
+
|
158
183
|
# runs a block error free
|
159
184
|
# (returns nil if exception happens)
|
160
185
|
def runef *args, &block
|
@@ -209,6 +234,9 @@ class Rubyment
|
|
209
234
|
# in this right moment it is not
|
210
235
|
# yet possible to return the exception
|
211
236
|
# without printing (planned improvement)
|
237
|
+
# another desirable case is to output
|
238
|
+
# the exception, but don't return it;
|
239
|
+
# not yet possible.
|
212
240
|
# @param [splat] +args+, an splat whose elements are expected to be +blea_args+ and +blocks_args+:
|
213
241
|
# +blea_args+:: [Array] args to be used internally, which are expected to be:
|
214
242
|
# +exception_admitted+:: [Boolean]
|
@@ -342,31 +370,56 @@ class Rubyment
|
|
342
370
|
end
|
343
371
|
|
344
372
|
|
345
|
-
# reads a uri (if 'open-uri' available, otherwise, just do a normal File.read)
|
373
|
+
# reads a uri (if 'rest-client' or 'open-uri' available and they don't throw any exception, otherwise, just do a normal File.read)
|
346
374
|
# @param [Array] args, an +Array+ whose elements are expected to be:
|
347
|
-
# +uri+:: [String, nil] uri or path of the file
|
375
|
+
# +uri+:: [String, nil] uri or path of the file (empty string is assumed in the case of +nil+ given)
|
348
376
|
# +username+:: [String] basic http authentication username
|
349
377
|
# +password+:: [String] basic http authentication password
|
350
378
|
# +return_on_rescue+:: [Object] a default to return in the case of exceptions raised
|
351
379
|
# +return_on_directory_given+:: [Object] a default to return in the case uri is a directory. Defaults to true
|
380
|
+
# +skip_open_uri+:: [Boolean] don't bother trying to use 'open-uri' (but still tries to open an uri with 'rest-client'). Defaults to +false+ for open-closed principle respect, but advised to be set to +true+
|
381
|
+
# +payload+:: [String]
|
382
|
+
# +verify_ssl+:: [Boolean] defaults to +false+
|
383
|
+
# +headers+:: [Hash] +"Authorization"+ key will be added to it if +auth_user+ is given. Defaults to +{}+
|
384
|
+
# +method+:: [HTTP method] one of +:get+, +:method+, +:post+ or +:delete+. defaults to +:get+
|
385
|
+
# +timeout+:: [Fixnum, nil] defaults to +nil+
|
352
386
|
#
|
353
387
|
# @return [String, Object] read data (or +return_on_rescue+)
|
354
388
|
def file_read args=ARGV
|
355
|
-
uri,
|
356
|
-
|
389
|
+
uri,
|
390
|
+
username,
|
391
|
+
password,
|
392
|
+
return_on_rescue,
|
393
|
+
return_on_directory_given,
|
394
|
+
skip_open_uri,
|
395
|
+
payload,
|
396
|
+
verify_ssl,
|
397
|
+
headers,
|
398
|
+
method,
|
399
|
+
timeout,
|
400
|
+
reserved = args
|
401
|
+
uri = uri.nne ""
|
357
402
|
file_is_directory = File.directory?(uri)
|
358
403
|
return_on_directory_given ||= true
|
359
|
-
contents = !(file_is_directory) &&
|
404
|
+
contents = !(file_is_directory) && (
|
360
405
|
begin
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
406
|
+
(send :rest_request_or_open_uri_open, [
|
407
|
+
uri,
|
408
|
+
payload,
|
409
|
+
verify_ssl,
|
410
|
+
headers,
|
411
|
+
method,
|
412
|
+
username,
|
413
|
+
password,
|
414
|
+
timeout,
|
415
|
+
skip_open_uri,
|
416
|
+
]).first
|
417
|
+
rescue => e1
|
418
|
+
begin
|
419
|
+
File.read uri
|
420
|
+
rescue => e2
|
421
|
+
return_on_rescue
|
422
|
+
end
|
370
423
|
end
|
371
424
|
) || (file_is_directory) && (return_on_directory_given)
|
372
425
|
end
|
@@ -808,43 +861,144 @@ class Rubyment
|
|
808
861
|
|
809
862
|
|
810
863
|
# makes a rest request.
|
811
|
-
#
|
864
|
+
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
865
|
+
# +url+:: [String]
|
866
|
+
# +payload+:: [String]
|
867
|
+
# +verify_ssl+:: [Boolean]
|
868
|
+
# +headers+:: [Hash] +"Authorization"+ key will be added to it if +auth_user+ is given.
|
869
|
+
# +method+:: [HTTP method] one of +:get+, +:method+, +:post+ or +:delete+
|
870
|
+
# +auth_user+:: [String, nil] username for basic authentication method
|
871
|
+
# +password+:: [String, nil] password for basic authentication method. Will prompt without echo if +nil+ and +auth_user+ is not +nil+
|
872
|
+
# +timeout+:: [Fixnum]
|
873
|
+
# @return [String] the response
|
812
874
|
def rest_request args=ARGV
|
813
875
|
require 'base64'
|
814
876
|
require 'rest-client'
|
815
|
-
|
877
|
+
|
816
878
|
stderr = @memory[:stderr]
|
817
879
|
time = @memory[:time]
|
880
|
+
url,
|
881
|
+
payload,
|
882
|
+
verify_ssl,
|
883
|
+
headers,
|
884
|
+
method,
|
885
|
+
auth_user,
|
886
|
+
password,
|
887
|
+
timeout,
|
888
|
+
reserved = args
|
889
|
+
|
890
|
+
auth_user = auth_user.nne
|
891
|
+
password = password.nne
|
892
|
+
method = method.nne :get
|
893
|
+
headers = headers.nne({})
|
894
|
+
base64_auth = Base64.encode64 [
|
895
|
+
auth_user,
|
896
|
+
auth_user && (input_single_line_non_echo [password])
|
897
|
+
].join ":"
|
898
|
+
auth_user && (headers["Authorization"] = "Basic #{base64_auth}")
|
899
|
+
request_execution = RestClient::Request.execute(:method => method, :url => url, :payload => payload, :headers => headers, :verify_ssl => verify_ssl, :timeout => timeout)
|
900
|
+
request_execution.to_s
|
901
|
+
end
|
902
|
+
|
903
|
+
|
904
|
+
# calls #rest_request (which depends on +'rest-client'+ gem)
|
905
|
+
# in the case it throws an exception, tries to call
|
906
|
+
# +'open-uri'+'s #open.
|
907
|
+
# note that not the arguments below refer to the #rest_request
|
908
|
+
# for #open, only +auth_user+ and +password+ will be
|
909
|
+
# forwarded, as they come to this function.
|
910
|
+
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
911
|
+
# +url+:: [String]
|
912
|
+
# +payload+:: [String]
|
913
|
+
# +verify_ssl+:: [Boolean] defaults to +false+
|
914
|
+
# +headers+:: [Hash] +"Authorization"+ key will be added to it if +auth_user+ is given. Defaults to +{}+
|
915
|
+
# +method+:: [HTTP method] one of +:get+, +:method+, +:post+ or +:delete+. defaults to +:get+
|
916
|
+
# +auth_user+:: [String, nil] username for basic authentication method
|
917
|
+
# +password+:: [String, nil] password for basic authentication method. Will prompt without echo if +nil+ and +auth_user+ is not +nil+
|
918
|
+
# +timeout+:: [Fixnum, nil] defaults to +nil+
|
919
|
+
# +skip_open_uri+:: [Boolean] don't bother trying with #open
|
920
|
+
# @return [Array] the response
|
921
|
+
def rest_request_or_open_uri_open args=ARGV
|
922
|
+
url,
|
923
|
+
payload,
|
924
|
+
verify_ssl,
|
925
|
+
headers,
|
926
|
+
method,
|
927
|
+
auth_user,
|
928
|
+
password,
|
929
|
+
timeout,
|
930
|
+
skip_open_uri,
|
931
|
+
reserved = args
|
932
|
+
skip_open_uri = skip_open_uri.nne
|
933
|
+
|
934
|
+
response = runea ["yes, rescue",
|
935
|
+
"output exception".negate_me,
|
936
|
+
"nil on exception"
|
937
|
+
] {
|
938
|
+
send :rest_request, [
|
939
|
+
url,
|
940
|
+
payload,
|
941
|
+
verify_ssl,
|
942
|
+
headers,
|
943
|
+
method,
|
944
|
+
auth_user,
|
945
|
+
password,
|
946
|
+
timeout,
|
947
|
+
]
|
948
|
+
}
|
949
|
+
response ||= runea ["yes, rescue".negate_me,
|
950
|
+
"output exception".negate_me,
|
951
|
+
"nil on exception"
|
952
|
+
] {
|
953
|
+
!skip_open_uri && send(
|
954
|
+
:open,
|
955
|
+
url,
|
956
|
+
:http_basic_authentication => [auth_user, password],
|
957
|
+
).read
|
958
|
+
}
|
959
|
+
[response]
|
960
|
+
end
|
961
|
+
|
962
|
+
|
963
|
+
# test #rest_request
|
964
|
+
# for now, the parameters must still be hardcoded.
|
965
|
+
def test__rest_request args=ARGV
|
966
|
+
require 'json'
|
967
|
+
stderr = @memory[:stderr]
|
818
968
|
|
819
969
|
atlasian_account="my_atlasian_account"
|
820
970
|
jira_host = "https://mydomain.atlassian.net/"
|
821
971
|
issue = "JIRAISSUE-6517"
|
822
972
|
url = "#{jira_host}/rest/api/2/issue/#{issue}/comment"
|
823
|
-
|
824
|
-
# 1) programmatically: let pw in plain text:
|
825
|
-
# auth = "my_user:my_pw"
|
826
|
-
# base64_auth = Base64.encode64 auth
|
827
|
-
# 2) a bit safer (this hash can be still used
|
828
|
-
# to hijack your account):
|
829
|
-
# echo "my_user:my_pw" | base64 # let a whitespace in the beginning
|
830
|
-
base64_auth = "bXlfdXNlcjpteV9wdwo="
|
831
|
-
# todo: it has to be interactive, or fetch from a keying
|
832
|
-
# to achieve good security standards
|
833
|
-
method = :get
|
834
|
-
method = :post
|
835
|
-
timeout = 2000
|
836
|
-
headers = {"Authorization" => "Basic #{base64_auth}" }
|
837
|
-
verify_ssl = true
|
973
|
+
|
838
974
|
json =<<-ENDHEREDOC
|
839
975
|
{
|
840
976
|
"body" : "my comment"
|
841
977
|
}
|
842
978
|
ENDHEREDOC
|
843
979
|
payload = "#{json}"
|
844
|
-
|
980
|
+
|
981
|
+
auth_user = nil
|
982
|
+
password = nil
|
983
|
+
method = :get
|
984
|
+
method = :post
|
985
|
+
timeout = 2000
|
986
|
+
verify_ssl = false
|
987
|
+
payload = "#{json}"
|
988
|
+
headers = ""
|
989
|
+
request_execution = send :rest_request, [
|
990
|
+
url,
|
991
|
+
payload,
|
992
|
+
verify_ssl,
|
993
|
+
headers,
|
994
|
+
method,
|
995
|
+
auth_user,
|
996
|
+
password,
|
997
|
+
timeout,
|
998
|
+
]
|
845
999
|
parsed_json = JSON.parse request_execution.to_s
|
846
1000
|
stderr.puts parsed_json
|
847
|
-
parsed_json
|
1001
|
+
[parsed_json]
|
848
1002
|
end
|
849
1003
|
|
850
1004
|
|
@@ -2540,10 +2694,10 @@ require '#{gem_name}'
|
|
2540
2694
|
extra_cert_pem_files,
|
2541
2695
|
output_exception,
|
2542
2696
|
reserved = args
|
2543
|
-
debug
|
2544
|
-
extra_cert_pem_files
|
2545
|
-
admit_plain
|
2546
|
-
output_exception
|
2697
|
+
debug = debug.nne
|
2698
|
+
extra_cert_pem_files = extra_cert_pem_files.nne []
|
2699
|
+
admit_plain = admit_plain.nne
|
2700
|
+
output_exception = (
|
2547
2701
|
output_exception.nne || admit_plain.negate_me
|
2548
2702
|
)
|
2549
2703
|
debug && (stderr.puts "#{__method__} starting")
|
@@ -2562,7 +2716,7 @@ require '#{gem_name}'
|
|
2562
2716
|
|
2563
2717
|
require 'socket'
|
2564
2718
|
plain_server = TCPServer.new ip_addr, listening_port
|
2565
|
-
ssl_server = runea [admit_plain, output_exception] {
|
2719
|
+
ssl_server = runea [admit_plain, output_exception, "nil on exception"] {
|
2566
2720
|
require 'openssl'
|
2567
2721
|
ssl_context = OpenSSL::SSL::SSLContext.new
|
2568
2722
|
ssl_context.extra_chain_cert =
|
@@ -2578,8 +2732,10 @@ require '#{gem_name}'
|
|
2578
2732
|
ssl_server
|
2579
2733
|
}
|
2580
2734
|
|
2735
|
+
rv = ssl_server || admit_plain && plain_server
|
2736
|
+
debug && (stderr.puts "will return #{rv}")
|
2581
2737
|
debug && (stderr.puts "#{__method__} returning")
|
2582
|
-
|
2738
|
+
rv
|
2583
2739
|
end
|
2584
2740
|
|
2585
2741
|
|
@@ -2622,7 +2778,13 @@ require '#{gem_name}'
|
|
2622
2778
|
debug.nne && (stderr.puts server)
|
2623
2779
|
Thread.start {
|
2624
2780
|
loop {
|
2625
|
-
|
2781
|
+
client = runea ["yes, rescue",
|
2782
|
+
"yes, output exception",
|
2783
|
+
"nil on exception"
|
2784
|
+
] {
|
2785
|
+
server.accept
|
2786
|
+
}
|
2787
|
+
Thread.start(client) { |client|
|
2626
2788
|
debug.nne && (stderr.puts Thread.current)
|
2627
2789
|
debug.nne && (stderr.puts client)
|
2628
2790
|
runoe {
|
@@ -2697,10 +2859,10 @@ require '#{gem_name}'
|
|
2697
2859
|
http_server_port,
|
2698
2860
|
http_ip_addr,
|
2699
2861
|
reserved = args
|
2700
|
-
http_processing_method
|
2701
|
-
http_processing_method_args
|
2702
|
-
http_server_port
|
2703
|
-
http_ip_addr
|
2862
|
+
http_processing_method = http_processing_method.nne :http_OK_response
|
2863
|
+
http_processing_method_args = http_processing_method_args.nne []
|
2864
|
+
http_server_port = http_server_port.nne 8003
|
2865
|
+
http_ip_addr = http_ip_addr.nne "0"
|
2704
2866
|
thread = tcp_server_plain [
|
2705
2867
|
http_server_port,
|
2706
2868
|
http_ip_addr,
|
@@ -2728,10 +2890,10 @@ require '#{gem_name}'
|
|
2728
2890
|
http_server_port,
|
2729
2891
|
http_ip_addr,
|
2730
2892
|
reserved = args
|
2731
|
-
http_processing_method
|
2732
|
-
http_processing_method_args
|
2733
|
-
http_server_port
|
2734
|
-
http_ip_addr
|
2893
|
+
http_processing_method = http_processing_method.nne :http_OK_response
|
2894
|
+
http_processing_method_args = http_processing_method_args.nne []
|
2895
|
+
http_server_port = http_server_port.nne 8003
|
2896
|
+
http_ip_addr = http_ip_addr.nne "0"
|
2735
2897
|
thread = tcp_ssl_server [
|
2736
2898
|
http_server_port,
|
2737
2899
|
http_ip_addr,
|
@@ -2893,16 +3055,16 @@ n8mFEtUKobsK
|
|
2893
3055
|
extra_cert_pem_files,
|
2894
3056
|
ssl_cert_pkey_chain_method,
|
2895
3057
|
reserved = args
|
2896
|
-
http_processing_method
|
2897
|
-
http_processing_method_args
|
2898
|
-
http_server_port
|
2899
|
-
http_ip_addr
|
2900
|
-
ssl_cert_pkey_chain_method
|
3058
|
+
http_processing_method = http_processing_method.nne :http_OK_response
|
3059
|
+
http_processing_method_args = http_processing_method_args.nne []
|
3060
|
+
http_server_port = http_server_port.nne 8003
|
3061
|
+
http_ip_addr = http_ip_addr.nne "0"
|
3062
|
+
ssl_cert_pkey_chain_method =
|
2901
3063
|
ssl_cert_pkey_chain_method.nne :ssl_sample_self_signed_cert_encrypted
|
2902
3064
|
ssl_cert_pkey_chain = send ssl_cert_pkey_chain_method
|
2903
|
-
priv_pemfile
|
2904
|
-
cert_pem_file
|
2905
|
-
extra_cert_pem_files
|
3065
|
+
priv_pemfile = priv_pemfile.nne ssl_cert_pkey_chain[1]
|
3066
|
+
cert_pem_file = cert_pem_file.nne ssl_cert_pkey_chain[0]
|
3067
|
+
extra_cert_pem_files = extra_cert_pem_files.nne ssl_cert_pkey_chain[2]
|
2906
3068
|
thread = tcp_ssl_server [
|
2907
3069
|
http_server_port,
|
2908
3070
|
http_ip_addr,
|
@@ -2940,8 +3102,8 @@ n8mFEtUKobsK
|
|
2940
3102
|
# the file.
|
2941
3103
|
def test__file_read__return_on_rescue args=ARGV
|
2942
3104
|
priv_pemfile, cert_pem_file = args
|
2943
|
-
priv_pemfile
|
2944
|
-
cert_pem_file
|
3105
|
+
priv_pemfile = priv_pemfile.nne "/tmp/pkey.pem"
|
3106
|
+
cert_pem_file = cert_pem_file.nne "/tmp/cert.crt"
|
2945
3107
|
runef {
|
2946
3108
|
File.delete priv_pemfile
|
2947
3109
|
File.delete cert_pem_file
|
@@ -3008,6 +3170,173 @@ n8mFEtUKobsK
|
|
3008
3170
|
end
|
3009
3171
|
|
3010
3172
|
|
3173
|
+
# test for tcp_ssl_server (calling an +io_method+,
|
3174
|
+
# by default #io_transform, with
|
3175
|
+
# a function that processes an http request and returns
|
3176
|
+
# an http_response, by default #http_OK_response)
|
3177
|
+
# just like #test__tcp_ssl_server__non_ssl,
|
3178
|
+
# calling directly #tcp_ssl_server, but making
|
3179
|
+
# mandatory the server to be ssl one.
|
3180
|
+
# requires, by default that the certificate and its
|
3181
|
+
# private key are found in the current dir, which
|
3182
|
+
# can be achieved with:
|
3183
|
+
# +openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout pkey.pem -out cert.crt+
|
3184
|
+
# but if the files don't exist, they will be created
|
3185
|
+
# with a sample self signed certificate.
|
3186
|
+
def test__tcp_ssl_server__io_method args = ARGV
|
3187
|
+
http_processing_method,
|
3188
|
+
http_processing_method_args,
|
3189
|
+
http_server_port,
|
3190
|
+
http_ip_addr,
|
3191
|
+
priv_pemfile,
|
3192
|
+
cert_pem_file,
|
3193
|
+
extra_cert_pem_files,
|
3194
|
+
ssl_cert_pkey_chain_method,
|
3195
|
+
debug,
|
3196
|
+
happy_with_request,
|
3197
|
+
io_method,
|
3198
|
+
io_method_debug,
|
3199
|
+
admit_non_ssl,
|
3200
|
+
reserved = args
|
3201
|
+
http_processing_method = http_processing_method.nne :http_OK_response
|
3202
|
+
http_processing_method_args = http_processing_method_args.nne []
|
3203
|
+
http_server_port = http_server_port.nne 8003
|
3204
|
+
http_ip_addr = http_ip_addr.nne "0"
|
3205
|
+
ssl_cert_pkey_chain_method =
|
3206
|
+
ssl_cert_pkey_chain_method.nne :ssl_sample_self_signed_cert_encrypted
|
3207
|
+
ssl_cert_pkey_chain = send ssl_cert_pkey_chain_method
|
3208
|
+
priv_pemfile = priv_pemfile.nne ssl_cert_pkey_chain[1]
|
3209
|
+
cert_pem_file = cert_pem_file.nne ssl_cert_pkey_chain[0]
|
3210
|
+
extra_cert_pemiles = extra_cert_pem_files.nne ssl_cert_pkey_chain[2]
|
3211
|
+
debug = debug.nne "yes, debug"
|
3212
|
+
io_method = io_method.nne "io_transform"
|
3213
|
+
io_method_debug = io_method_debug.nne debug
|
3214
|
+
happy_with_request = happy_with_request.nne
|
3215
|
+
admit_non_ssl = admit_non_ssl.nne
|
3216
|
+
tcp_ssl_server_args = [
|
3217
|
+
http_server_port,
|
3218
|
+
http_ip_addr,
|
3219
|
+
debug,
|
3220
|
+
admit_non_ssl,
|
3221
|
+
io_method,
|
3222
|
+
[
|
3223
|
+
io_method_debug,
|
3224
|
+
happy_with_request,
|
3225
|
+
http_processing_method,
|
3226
|
+
http_processing_method_args
|
3227
|
+
],
|
3228
|
+
priv_pemfile,
|
3229
|
+
cert_pem_file,
|
3230
|
+
extra_cert_pem_files,
|
3231
|
+
"yes, output exceptions",
|
3232
|
+
]
|
3233
|
+
thread = tcp_ssl_server tcp_ssl_server_args
|
3234
|
+
[ thread ] + tcp_ssl_server_args
|
3235
|
+
end
|
3236
|
+
|
3237
|
+
|
3238
|
+
# tests file_read against a uri.
|
3239
|
+
# created to test a client for servers
|
3240
|
+
# created with
|
3241
|
+
# #test__tcp_ssl_server__io_method
|
3242
|
+
def test__file_read__uri_root args = ARGV
|
3243
|
+
stderr = @memory[:stderr]
|
3244
|
+
domain,
|
3245
|
+
http_server_port,
|
3246
|
+
admit_non_ssl,
|
3247
|
+
debug,
|
3248
|
+
reserved = args
|
3249
|
+
domain = domain.nne "localhost"
|
3250
|
+
http_server_port = http_server_port.nne 8003
|
3251
|
+
admit_non_ssl = admit_non_ssl.nne true
|
3252
|
+
debug = debug.nne
|
3253
|
+
stderr.puts admit_non_ssl.inspect
|
3254
|
+
stderr.puts (admit_non_ssl && (file_read ["http://#{domain}:#{http_server_port}/"])).inspect
|
3255
|
+
response = (file_read ["https://#{domain}:#{http_server_port}/"]) ||
|
3256
|
+
admit_non_ssl && (file_read ["http://#{domain}:#{http_server_port}/"])
|
3257
|
+
debug && (stderr.puts "response{#{response}}response")
|
3258
|
+
response
|
3259
|
+
end
|
3260
|
+
|
3261
|
+
|
3262
|
+
# tests test__tcp_ssl_server__io_method and opens
|
3263
|
+
# another thread for the client
|
3264
|
+
def test__tcp_ssl_server__get_root args = ARGV
|
3265
|
+
stderr = @memory[:stderr]
|
3266
|
+
tcp_ssl_server_method,
|
3267
|
+
http_processing_method,
|
3268
|
+
http_processing_method_args,
|
3269
|
+
http_server_port,
|
3270
|
+
http_ip_addr,
|
3271
|
+
priv_pemfile,
|
3272
|
+
cert_pem_file,
|
3273
|
+
extra_cert_pem_files,
|
3274
|
+
ssl_cert_pkey_chain_method,
|
3275
|
+
debug_tcp_ssl_server_method,
|
3276
|
+
happy_with_request,
|
3277
|
+
io_method,
|
3278
|
+
io_method_debug,
|
3279
|
+
domain,
|
3280
|
+
admit_non_ssl,
|
3281
|
+
no_debug_client,
|
3282
|
+
reserved = args
|
3283
|
+
tcp_ssl_server_method = tcp_ssl_server_method.nne :test__tcp_ssl_server__io_method
|
3284
|
+
domain = domain.nne "localhost"
|
3285
|
+
http_server_port = http_server_port.nne 8003
|
3286
|
+
no_debug_client = no_debug_client.nne
|
3287
|
+
server_thread = send tcp_ssl_server_method,
|
3288
|
+
[
|
3289
|
+
http_processing_method,
|
3290
|
+
http_processing_method_args,
|
3291
|
+
http_server_port,
|
3292
|
+
http_ip_addr,
|
3293
|
+
priv_pemfile,
|
3294
|
+
cert_pem_file,
|
3295
|
+
extra_cert_pem_files,
|
3296
|
+
ssl_cert_pkey_chain_method,
|
3297
|
+
debug_tcp_ssl_server_method,
|
3298
|
+
happy_with_request,
|
3299
|
+
io_method,
|
3300
|
+
io_method_debug,
|
3301
|
+
admit_non_ssl,
|
3302
|
+
]
|
3303
|
+
|
3304
|
+
thread_2 = Thread.new {
|
3305
|
+
loop {
|
3306
|
+
response = test__file_read__uri_root [
|
3307
|
+
domain,
|
3308
|
+
http_server_port,
|
3309
|
+
admit_non_ssl,
|
3310
|
+
no_debug_client.negate_me,
|
3311
|
+
]
|
3312
|
+
sleep 2
|
3313
|
+
}
|
3314
|
+
}
|
3315
|
+
server_thread.first.join
|
3316
|
+
|
3317
|
+
true
|
3318
|
+
end
|
3319
|
+
|
3320
|
+
|
3321
|
+
# experimental stuff coming. usage example:
|
3322
|
+
# ./rubyment.rb invoke_double p test__shell_send_array__main "tinga" "" sub in EN
|
3323
|
+
# ["tENga"]
|
3324
|
+
def test__shell_send_array__main args=[]
|
3325
|
+
p args
|
3326
|
+
object_to_send,
|
3327
|
+
reserved,
|
3328
|
+
method_to_send,
|
3329
|
+
*args_to_send = args
|
3330
|
+
object_to_send = object_to_send.nne
|
3331
|
+
method_to_send = method_to_send.nne :main
|
3332
|
+
object_to_send && (
|
3333
|
+
object_to_send.send method_to_send, *args_to_send
|
3334
|
+
) || (!object_to_send) && (
|
3335
|
+
send method_to_send, args_to_send
|
3336
|
+
)
|
3337
|
+
end
|
3338
|
+
|
3339
|
+
|
3011
3340
|
# test for Object::nne
|
3012
3341
|
def test__object_nne args = ARGV
|
3013
3342
|
string_neutral = ""
|
@@ -3086,6 +3415,51 @@ n8mFEtUKobsK
|
|
3086
3415
|
end
|
3087
3416
|
|
3088
3417
|
|
3418
|
+
# test #rest_request
|
3419
|
+
# for now, the parameters must still be hardcoded.
|
3420
|
+
def test__rest_request__with_ayt args=ARGV
|
3421
|
+
require 'json'
|
3422
|
+
stderr = @memory[:stderr]
|
3423
|
+
|
3424
|
+
url = "https://owl.loftweb.nl:55031/4/3-roOomydev"
|
3425
|
+
json =<<-ENDHEREDOC
|
3426
|
+
{
|
3427
|
+
"operation" : "AYT",
|
3428
|
+
"version" : {
|
3429
|
+
"client" : "X",
|
3430
|
+
"protocol" : {
|
3431
|
+
"domain_model" : "4",
|
3432
|
+
"API" : "3"
|
3433
|
+
}
|
3434
|
+
}
|
3435
|
+
}
|
3436
|
+
ENDHEREDOC
|
3437
|
+
payload = "#{json}"
|
3438
|
+
|
3439
|
+
auth_user = "web"
|
3440
|
+
password = "vadim"
|
3441
|
+
method = :post
|
3442
|
+
method = :get
|
3443
|
+
timeout = 600
|
3444
|
+
verify_ssl = true
|
3445
|
+
payload = "#{json}"
|
3446
|
+
headers = ""
|
3447
|
+
request_execution = send :rest_request, [
|
3448
|
+
url,
|
3449
|
+
payload,
|
3450
|
+
verify_ssl,
|
3451
|
+
headers,
|
3452
|
+
method,
|
3453
|
+
auth_user,
|
3454
|
+
password,
|
3455
|
+
timeout,
|
3456
|
+
]
|
3457
|
+
parsed_json = JSON.parse request_execution.to_s
|
3458
|
+
stderr.puts parsed_json
|
3459
|
+
[parsed_json]
|
3460
|
+
end
|
3461
|
+
|
3462
|
+
|
3089
3463
|
end
|
3090
3464
|
|
3091
3465
|
(__FILE__ == $0) && Rubyment.new({:invoke => ARGV})
|