ambidexter 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ambidexter +15 -0
- data/lib/application.rb +17 -0
- data/lib/client.rb +148 -0
- data/lib/server.rb +75 -0
- metadata +9 -7
- data/bin/greet +0 -4
- data/lib/ambidexter.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc9e99ab8aeb4e9da3074f0bf294812f08c8f60
|
4
|
+
data.tar.gz: 8d26a8ad0319c7d176dca815a7f32b7446b54e7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f81d14ca193b4ae000931e74b37501fd1aefbec93a2f11836c8ba7a7b555a41ea1308507a8360989f26caccc4eb60eeccea62c6639122bb8c18e5d8791bb60b9
|
7
|
+
data.tar.gz: 4fc109396b56b3c0bbe6fb8306b9dc66459467c36c943da042fd5aca75cd6a34ae98c57db69eae352826b23915c7762e26d1014cd1110d0f9e69320f550869a0
|
data/bin/ambidexter
ADDED
data/lib/application.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Application
|
2
|
+
class LoremIpsum
|
3
|
+
def self.lorem
|
4
|
+
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
5
|
+
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
6
|
+
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
7
|
+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
8
|
+
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
|
9
|
+
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def blank?(value)
|
15
|
+
value.nil? || value.strip.empty?
|
16
|
+
end
|
17
|
+
end
|
data/lib/client.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
require "application"
|
2
|
+
require "curb"
|
3
|
+
require "colorize"
|
4
|
+
|
5
|
+
class Client < Application
|
6
|
+
def initialize
|
7
|
+
# Setting IP of server
|
8
|
+
print "Input IP address of servrer: ".green
|
9
|
+
@ip = $stdin.gets.chomp
|
10
|
+
@ip = 'localhost' if blank? @ip
|
11
|
+
|
12
|
+
# Setting PORT of server
|
13
|
+
print "Input Port of servrer: ".green
|
14
|
+
@port = $stdin.gets.chomp
|
15
|
+
@port = '5899' if blank? @port
|
16
|
+
|
17
|
+
# Setting eterations count
|
18
|
+
print "Input eterations count: ".green
|
19
|
+
@each_count = $stdin.gets.chomp.to_i
|
20
|
+
@each_count = 1 if @each_count.zero?
|
21
|
+
|
22
|
+
# Setting eterations count
|
23
|
+
print "Input threads count: ".green
|
24
|
+
@threads_count = $stdin.gets.chomp.to_i
|
25
|
+
@threads_count = 1 if @threads_count.zero?
|
26
|
+
|
27
|
+
# Building link
|
28
|
+
@uri = "http://#{@ip}:#{@port}"
|
29
|
+
|
30
|
+
# Thread and time arrays
|
31
|
+
@req_times = []
|
32
|
+
@threads = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def test
|
36
|
+
@threads_count.times do
|
37
|
+
@threads << Thread.new do
|
38
|
+
@each_count.times do
|
39
|
+
# Raw root GET
|
40
|
+
t = Time.now
|
41
|
+
response = Curl.get(@uri)
|
42
|
+
@req_times << Time.now - t
|
43
|
+
if response.status == '200 OK'
|
44
|
+
print '.'.green
|
45
|
+
else
|
46
|
+
print '!'.red
|
47
|
+
end
|
48
|
+
|
49
|
+
# Root POST with correct params
|
50
|
+
t = Time.now
|
51
|
+
response = Curl.post(@uri, { name: 'Oleg', github_nickname: 'sorefull' })
|
52
|
+
@req_times << Time.now - t
|
53
|
+
if response.status == '202 Accepted'
|
54
|
+
print '.'.green
|
55
|
+
else
|
56
|
+
print '!'.red
|
57
|
+
end
|
58
|
+
|
59
|
+
# Root POST with wrong params
|
60
|
+
t = Time.now
|
61
|
+
response = Curl.post(@uri, { name: '', github_nickname: '' })
|
62
|
+
@req_times << Time.now - t
|
63
|
+
if response.status == '401 Unauthorized'
|
64
|
+
print '.'.green
|
65
|
+
else
|
66
|
+
print '!'.red
|
67
|
+
end
|
68
|
+
|
69
|
+
# Lorem GET with body check
|
70
|
+
t = Time.now
|
71
|
+
response = Curl.get(@uri + '/lorem')
|
72
|
+
@req_times << Time.now - t
|
73
|
+
if response.body == LoremIpsum.lorem
|
74
|
+
print '.'.green
|
75
|
+
else
|
76
|
+
print '!'.red
|
77
|
+
end
|
78
|
+
|
79
|
+
# Lorem GET with params
|
80
|
+
t = Time.now
|
81
|
+
response = Curl.get(@uri + '/lorem', { length: 10 })
|
82
|
+
@req_times << Time.now - t
|
83
|
+
if response.body == LoremIpsum.lorem[0..10]
|
84
|
+
print '.'.green
|
85
|
+
else
|
86
|
+
print '!'.red
|
87
|
+
end
|
88
|
+
|
89
|
+
# Cookie GET with correct cookies
|
90
|
+
t = Time.now
|
91
|
+
response = Curl.get(@uri + '/cookie') do |http|
|
92
|
+
http.headers['Cookie'] = 'private=asdfg; public=gijj'
|
93
|
+
end
|
94
|
+
@req_times << Time.now - t
|
95
|
+
if response.status == '200 OK'
|
96
|
+
print '.'.green
|
97
|
+
else
|
98
|
+
print '!'.red
|
99
|
+
end
|
100
|
+
|
101
|
+
# Cookie GET with wrong cookies
|
102
|
+
t = Time.now
|
103
|
+
response = Curl.get(@uri + '/cookie') do |http|
|
104
|
+
http.headers['Cookie'] = 'private=wrong; public=wrong'
|
105
|
+
end
|
106
|
+
@req_times << Time.now - t
|
107
|
+
if response.status == '401 Unauthorized'
|
108
|
+
print '.'.green
|
109
|
+
else
|
110
|
+
print '!'.red
|
111
|
+
end
|
112
|
+
|
113
|
+
# File GET
|
114
|
+
file_name = '/file.txt'
|
115
|
+
t = Time.now
|
116
|
+
response = Curl.get(@uri + file_name)
|
117
|
+
@req_times << Time.now - t
|
118
|
+
file = File.open("./files#{file_name}", 'r')
|
119
|
+
if response.body == file.read && response.status == '200 OK'
|
120
|
+
print '.'.green
|
121
|
+
else
|
122
|
+
print '!'.red
|
123
|
+
end
|
124
|
+
|
125
|
+
# File POST
|
126
|
+
file_name = 'image.jpeg'
|
127
|
+
response = Curl::Easy.new(@uri + '/file')
|
128
|
+
response.multipart_form_post = true
|
129
|
+
t = Time.now
|
130
|
+
response.http_post(Curl::PostField.file('uploaded_image', "./files/#{file_name}"))
|
131
|
+
@req_times << Time.now - t
|
132
|
+
if response.status == '200 OK'
|
133
|
+
print '.'.green
|
134
|
+
else
|
135
|
+
print '!'.red
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Joining threads
|
142
|
+
@threads.each {|thread| thread.join}
|
143
|
+
end
|
144
|
+
|
145
|
+
def result
|
146
|
+
@req_times
|
147
|
+
end
|
148
|
+
end
|
data/lib/server.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "application"
|
2
|
+
require "webrick"
|
3
|
+
include WEBrick
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
class Server < Application
|
7
|
+
class RootPath < WEBrick::HTTPServlet::AbstractServlet
|
8
|
+
def do_GET(request, response)
|
9
|
+
response.status = 200
|
10
|
+
end
|
11
|
+
def do_POST(request, response)
|
12
|
+
if request.query == { "name"=>"Oleg", "github_nickname"=>"sorefull"}
|
13
|
+
response.status = 202
|
14
|
+
else
|
15
|
+
response.status = 401
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class LoremPath < WEBrick::HTTPServlet::AbstractServlet
|
21
|
+
def do_GET(request, response)
|
22
|
+
length = request.query['length'].to_i
|
23
|
+
length = -1 if length < 1
|
24
|
+
response.body = Server::LoremIpsum.lorem[0..length]
|
25
|
+
response.status = 200
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class CookiePath < WEBrick::HTTPServlet::AbstractServlet
|
30
|
+
def do_GET(request, response)
|
31
|
+
if request.cookies.select{|c| c.name == 'private'}.first.value == 'asdfg' &&
|
32
|
+
request.cookies.select{|c| c.name == 'public'}.first.value == 'gijj'
|
33
|
+
response.status = 200
|
34
|
+
else
|
35
|
+
response.status = 401
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class FilePath < WEBrick::HTTPServlet::AbstractServlet
|
41
|
+
def do_POST(request, response)
|
42
|
+
file_data = request.query["uploaded_image"]
|
43
|
+
random_string = SecureRandom.hex(3)
|
44
|
+
f = File.open("tmp/#{random_string}_image.jpeg", "wb")
|
45
|
+
f.syswrite file_data
|
46
|
+
f.close
|
47
|
+
response.status = FileUtils.compare_file("tmp/#{random_string}_image.jpeg", 'files/image.jpeg') ? 200 : 500
|
48
|
+
FileUtils.rm_rf("tmp/#{random_string}_image.jpeg")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize
|
53
|
+
print "Input Port of servrer: ".green
|
54
|
+
@port = $stdin.gets.chomp
|
55
|
+
@port = '5899' if blank? @port
|
56
|
+
FileUtils.rm_rf('tmp')
|
57
|
+
Dir.mkdir('tmp')
|
58
|
+
end
|
59
|
+
|
60
|
+
def mount
|
61
|
+
@server = HTTPServer.new(:Port => @port)
|
62
|
+
@server.mount "/", RootPath
|
63
|
+
@server.mount "/lorem", LoremPath
|
64
|
+
@server.mount "/cookie", CookiePath
|
65
|
+
@server.mount "/file", FilePath
|
66
|
+
@server.mount('/file.txt', WEBrick::HTTPServlet::DefaultFileHandler, './files/file.txt')
|
67
|
+
end
|
68
|
+
|
69
|
+
def start
|
70
|
+
['TERM', 'INT'].each do |signal|
|
71
|
+
trap(signal){ @server.shutdown }
|
72
|
+
end
|
73
|
+
@server.start
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ambidexter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Cherednichenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Ambidexter two hands and will give bouth to help you in testing
|
14
|
-
network for HTTP stuff
|
13
|
+
description: Ambidexter hands two hands and will give bouth to help you in testing
|
14
|
+
your network for HTTP stuff
|
15
15
|
email: olegh.cherednichenko@gmail.com
|
16
16
|
executables:
|
17
|
-
-
|
17
|
+
- ambidexter
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- bin/
|
22
|
-
- lib/
|
21
|
+
- bin/ambidexter
|
22
|
+
- lib/application.rb
|
23
|
+
- lib/client.rb
|
24
|
+
- lib/server.rb
|
23
25
|
homepage: http://rubygems.org/gems/ambidexter
|
24
26
|
licenses:
|
25
27
|
- MIT
|
data/bin/greet
DELETED