Module: TestServer::WebHelper

Included in:
ApplicationController
Defined in:
lib/test_server/web_helper.rb

Instance Method Summary collapse

Instance Method Details

#configure_cachingObject



23
24
25
26
27
28
29
# File 'lib/test_server/web_helper.rb', line 23

def configure_caching
  if params.key? 'expires'
    expires_in params[:expires].to_i, public: true, must_revalidate: true
  else
    expires_now
  end
end

#encode(params, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/test_server/web_helper.rb', line 31

def encode(params, &block)
  encoders = []
  encoders << Encoders::Base64.new
  encoders << Encoders::Base64Strict.new
  encoders << Encoders::Gzip.new

  encoders_to_run = params.symbolize_keys.keep_if {|_,v| v.to_bool == true }.keys & encoders.collect { |e| e.name }

  if encoders_to_run.blank?
    real_encoders = [Encoders::Null.new]
  else
    real_encoders = encoders_to_run.collect { |er| encoders.find { |e| e.name? er } }.compact
  end

  real_encoders.reduce(block.call) do |memo, e| 
    e.encode(memo)
  end
end

#generate_eicarObject



14
15
16
17
18
19
20
21
# File 'lib/test_server/web_helper.rb', line 14

def generate_eicar
  [ 'X', '5', 'O', '!', 'P', '%', '@', 'A', 'P', '[', '4', "\\", 'P',
    'Z', 'X', '5', '4', '(', 'P', '^', ')', '7', 'C', 'C', ')', '7',
    '}', '$', 'E', 'I', 'C', 'A', 'R', '-', 'S', 'T', 'A', 'N', 'D',
    'A', 'R', 'D', '-', 'A', 'N', 'T', 'I', 'V', 'I', 'R', 'U', 'S',
    '-', 'T', 'E', 'S', 'T', '-', 'F', 'I', 'L', 'E', '!', '$', 'H',
    '+', 'H', '*' ]
end

#generate_random_string(count) ⇒ Object



8
9
10
11
12
# File 'lib/test_server/web_helper.rb', line 8

def generate_random_string(count)
  o = [('a'..'z'), ('A'..'Z'), (1..9), %w{° ^ ! " § $ % & / ( ) = ? * + ~ ` ´ ' # > < | @ ł   ŧ    ŋ đ ð ſ ð đ ŋ ħ   ¢ « | » « ¢    µ ·   ĸ ¹ ² ³ ¼ ½ ¬ \{ [ ] \}}].map { |i| i.to_a }.flatten

  (0...count.to_i).map { o[rand(o.length)] }.join
end

#generate_string(count, string = "Plain Data\n") ⇒ Object



4
5
6
# File 'lib/test_server/web_helper.rb', line 4

def generate_string(count, string = "Plain Data\n")
  string * count.to_i
end