arpitjain11-rubycas-server 0.8.0.20090612

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/CHANGELOG.txt +1 -0
  2. data/History.txt +272 -0
  3. data/LICENSE.txt +504 -0
  4. data/Manifest.txt +85 -0
  5. data/PostInstall.txt +3 -0
  6. data/README.rdoc +26 -0
  7. data/Rakefile +4 -0
  8. data/bin/rubycas-server +13 -0
  9. data/bin/rubycas-server-ctl +9 -0
  10. data/config/hoe.rb +78 -0
  11. data/config/requirements.rb +15 -0
  12. data/config.example.yml +544 -0
  13. data/config.ru +38 -0
  14. data/custom_views.example.rb +11 -0
  15. data/lib/casserver/authenticators/active_directory_ldap.rb +11 -0
  16. data/lib/casserver/authenticators/base.rb +48 -0
  17. data/lib/casserver/authenticators/client_certificate.rb +46 -0
  18. data/lib/casserver/authenticators/google.rb +54 -0
  19. data/lib/casserver/authenticators/ldap.rb +147 -0
  20. data/lib/casserver/authenticators/ntlm.rb +88 -0
  21. data/lib/casserver/authenticators/open_id.rb +22 -0
  22. data/lib/casserver/authenticators/sql.rb +102 -0
  23. data/lib/casserver/authenticators/sql_encrypted.rb +76 -0
  24. data/lib/casserver/authenticators/sql_md5.rb +19 -0
  25. data/lib/casserver/authenticators/sql_rest_auth.rb +77 -0
  26. data/lib/casserver/authenticators/test.rb +19 -0
  27. data/lib/casserver/cas.rb +322 -0
  28. data/lib/casserver/conf.rb +75 -0
  29. data/lib/casserver/controllers.rb +457 -0
  30. data/lib/casserver/load_picnic.rb +19 -0
  31. data/lib/casserver/localization.rb +82 -0
  32. data/lib/casserver/models.rb +265 -0
  33. data/lib/casserver/postambles.rb +174 -0
  34. data/lib/casserver/utils.rb +30 -0
  35. data/lib/casserver/version.rb +9 -0
  36. data/lib/casserver/views.rb +245 -0
  37. data/lib/casserver.rb +58 -0
  38. data/lib/rubycas-server/version.rb +1 -0
  39. data/lib/rubycas-server.rb +1 -0
  40. data/po/de_DE/rubycas-server.po +119 -0
  41. data/po/es_ES/rubycas-server.po +115 -0
  42. data/po/fr_FR/rubycas-server.po +116 -0
  43. data/po/ja_JP/rubycas-server.po +118 -0
  44. data/po/pl_PL/rubycas-server.po +115 -0
  45. data/po/pt_BR/rubycas-server.po +115 -0
  46. data/po/ru_RU/rubycas-server.po +110 -0
  47. data/po/rubycas-server.pot +104 -0
  48. data/public/themes/cas.css +121 -0
  49. data/public/themes/notice.png +0 -0
  50. data/public/themes/ok.png +0 -0
  51. data/public/themes/simple/bg.png +0 -0
  52. data/public/themes/simple/login_box_bg.png +0 -0
  53. data/public/themes/simple/logo.png +0 -0
  54. data/public/themes/simple/theme.css +28 -0
  55. data/public/themes/urbacon/bg.png +0 -0
  56. data/public/themes/urbacon/login_box_bg.png +0 -0
  57. data/public/themes/urbacon/logo.png +0 -0
  58. data/public/themes/urbacon/theme.css +33 -0
  59. data/public/themes/warning.png +0 -0
  60. data/resources/init.d.sh +58 -0
  61. data/script/console +10 -0
  62. data/script/destroy +14 -0
  63. data/script/generate +14 -0
  64. data/script/txt2html +82 -0
  65. data/setup.rb +1585 -0
  66. data/tasks/deployment.rake +34 -0
  67. data/tasks/environment.rake +7 -0
  68. data/tasks/localization.rake +11 -0
  69. data/tasks/website.rake +17 -0
  70. data/vendor/isaac_0.9.1/LICENSE +26 -0
  71. data/vendor/isaac_0.9.1/README +78 -0
  72. data/vendor/isaac_0.9.1/TODO +3 -0
  73. data/vendor/isaac_0.9.1/VERSIONS +3 -0
  74. data/vendor/isaac_0.9.1/crypt/ISAAC.rb +171 -0
  75. data/vendor/isaac_0.9.1/isaac.gemspec +39 -0
  76. data/vendor/isaac_0.9.1/setup.rb +596 -0
  77. data/vendor/isaac_0.9.1/test/TC_ISAAC.rb +76 -0
  78. metadata +193 -0
@@ -0,0 +1,596 @@
1
+ require 'rbconfig'
2
+ require 'fileutils'
3
+ require 'pp'
4
+ require 'optparse'
5
+ require 'yaml'
6
+
7
+ module Package
8
+
9
+ class SpecificationError < StandardError; end
10
+ # forward declaration of the specification classes so we can keep all
11
+ # constants here
12
+ class PackageSpecification_1_0; end
13
+ # Default semantics
14
+ PackageSpecification = PackageSpecification_1_0
15
+
16
+ #TODO: could get this collected automatically with Class#inherited etc
17
+ SEMANTICS = { "1.0" => PackageSpecification_1_0 }
18
+
19
+ KINDS = [
20
+ :bin, :lib, :ext, :data, :conf, :doc
21
+ ]
22
+
23
+ #{{{ list of files to be ignored stolen from setup.rb
24
+ mapping = { '.' => '\.', '$' => '\$', '#' => '\#', '*' => '.*' }
25
+ ignore_files = %w[core RCSLOG tags TAGS .make.state .nse_depinfo
26
+ #* .#* cvslog.* ,* .del-* *.olb *~ *.old *.bak *.BAK *.orig *.rej _$* *$
27
+ *.org *.in .* ]
28
+ #end of robbery
29
+ IGNORE_FILES = ignore_files.map do |x|
30
+ Regexp.new('\A' + x.gsub(/[\.\$\#\*]/){|c| mapping[c]} + '\z')
31
+ end
32
+
33
+ def self.config(name)
34
+ # XXX use pathname
35
+ prefix = Regexp.quote(Config::CONFIG["prefix"])
36
+ exec_prefix = Regexp.quote(Config::CONFIG["exec_prefix"])
37
+ Config::CONFIG[name].gsub(/\A\/?(#{prefix}|#{exec_prefix})\/?/, '')
38
+ end
39
+
40
+ SITE_DIRS = {
41
+ :bin => config("bindir"),
42
+ :lib => config("sitelibdir"),
43
+ :ext => config("sitearchdir"),
44
+ :data => config("datadir"),
45
+ :conf => config("sysconfdir"),
46
+ :doc => File.join(config("datadir"), "doc"),
47
+ }
48
+
49
+ VENDOR_DIRS = {
50
+ :bin => config("bindir"),
51
+ :lib => config("rubylibdir"),
52
+ :ext => config("archdir"),
53
+ :data => config("datadir"),
54
+ :conf => config("sysconfdir"),
55
+ :doc => File.join(config("datadir"), "doc"),
56
+ }
57
+
58
+ MODES = {
59
+ :bin => 0755,
60
+ :lib => 0644,
61
+ :ext => 0755, # was: 0555,
62
+ :data => 0644,
63
+ :conf => 0644,
64
+ :doc => 0644,
65
+ }
66
+
67
+
68
+ SETUP_OPTIONS = {:parse_cmdline => true, :load_conf => true, :run_tasks => true}
69
+
70
+ def self.setup(version, options = {}, &instructions)
71
+ prefixes = dirs = nil
72
+ options = SETUP_OPTIONS.dup.update(options)
73
+
74
+ if options[:load_conf] && File.exist?("config.save")
75
+ config = YAML.load_file "config.save"
76
+ prefixes = config[:prefixes]
77
+ dirs = config[:dirs]
78
+ end
79
+
80
+ pkg = package_specification_with_semantics(version).new(prefixes, dirs)
81
+ pkg.parse_command_line if options[:parse_cmdline]
82
+ pkg.instance_eval(&instructions)
83
+
84
+ pkg.run_tasks if options[:run_tasks]
85
+
86
+ # pkg.install
87
+ pkg
88
+ end
89
+
90
+ def self.package_specification_with_semantics(version)
91
+ #XXX: implement the full x.y(.z)? semantics
92
+ r = SEMANTICS[version]
93
+ raise SpecificationError, "Unknown version #{version}." unless r
94
+ r
95
+ end
96
+
97
+
98
+ module Actions
99
+
100
+ class InstallFile
101
+
102
+ attr_reader :source, :destination, :mode
103
+
104
+ def initialize(source, destination, mode, options)
105
+ @source = source
106
+ @destination = destination
107
+ @mode = mode
108
+ @options = options
109
+ end
110
+
111
+ def install
112
+ FileUtils.install @source, File.join(@options.destdir, @destination),
113
+ {:verbose => @options.verbose,
114
+ :noop => @options.noop, :mode => @mode }
115
+ end
116
+
117
+ def hash
118
+ [@source.hash, @destination.hash].hash
119
+ end
120
+
121
+ def eql?(other)
122
+ self.class == other.class &&
123
+ @source == other.source &&
124
+ @destination == other.destination &&
125
+ @mode == other.mode
126
+ end
127
+
128
+ def <=>(other)
129
+ FULL_ORDER[self, other] || self.destination <=> other.destination
130
+ end
131
+ end
132
+
133
+ class MkDir
134
+
135
+ attr_reader :directory
136
+
137
+ def initialize(directory, options)
138
+ @directory = directory
139
+ @options = options
140
+ end
141
+
142
+ def install
143
+ FileUtils.mkdir_p File.join(@options.destdir, @directory),
144
+ {:verbose => @options.verbose,
145
+ :noop => @options.noop }
146
+ end
147
+
148
+ def <=>(other)
149
+ FULL_ORDER[self, other] || self.directory <=> other.directory
150
+ end
151
+ end
152
+
153
+ class FixShebang
154
+
155
+ attr_reader :destination
156
+
157
+ def initialize(destination, options)
158
+ @options = options
159
+ @destination = destination
160
+ end
161
+
162
+ def install
163
+ path = File.join(@options.destdir, @destination)
164
+ fix_shebang(path)
165
+ end
166
+
167
+ # taken from rpa-base, originally based on setup.rb's
168
+ # modify: #!/usr/bin/ruby
169
+ # modify: #! /usr/bin/ruby
170
+ # modify: #!ruby
171
+ # not modify: #!/usr/bin/env ruby
172
+ SHEBANG_RE = /\A\#!\s*\S*ruby\S*/
173
+
174
+ #TODO allow the ruby-prog to be placed in the shebang line to be passed as
175
+ # an option
176
+ def fix_shebang(path)
177
+ tmpfile = path + '.tmp'
178
+ begin
179
+ #XXX: needed at all?
180
+ # it seems that FileUtils doesn't expose its default output
181
+ # @fileutils_output = $stderr
182
+ # we might want to allow this to be redirected.
183
+ $stderr.puts "shebang:open #{tmpfile}" if @options.verbose
184
+ unless @options.noop
185
+ File.open(path) do |r|
186
+ File.open(tmpfile, 'w', 0755) do |w|
187
+ first = r.gets
188
+ return unless SHEBANG_RE =~ first
189
+ w.print first.sub(SHEBANG_RE, '#!' + Config::CONFIG['ruby-prog'])
190
+ w.write r.read
191
+ end
192
+ end
193
+ end
194
+ FileUtils.mv(tmpfile, path, :verbose => @options.verbose,
195
+ :noop => @options.noop)
196
+ ensure
197
+ FileUtils.rm_f(tmpfile, :verbose => @options.verbose,
198
+ :noop => @options.noop)
199
+ end
200
+ end
201
+
202
+ def <=>(other)
203
+ FULL_ORDER[self, other] || self.destination <=> other.destination
204
+ end
205
+
206
+ def hash
207
+ @destination.hash
208
+ end
209
+
210
+ def eql?(other)
211
+ self.class == other.class && self.destination == other.destination
212
+ end
213
+ end
214
+
215
+ order = [MkDir, InstallFile, FixShebang]
216
+ FULL_ORDER = lambda do |me, other|
217
+ a, b = order.index(me.class), order.index(other.class)
218
+ if a && b
219
+ (r = a - b) == 0 ? nil : r
220
+ else
221
+ -1 # arbitrary
222
+ end
223
+ end
224
+
225
+ class ActionList < Array
226
+
227
+ def directories!(options)
228
+ dirnames = []
229
+ map! { |d|
230
+ if d.kind_of?(InstallFile) && !dirnames.include?(File.dirname(d.destination))
231
+ dirnames << File.dirname(d.destination)
232
+ [MkDir.new(File.dirname(d.destination), options), d]
233
+ else
234
+ d
235
+ end
236
+ }
237
+ flatten!
238
+ end
239
+
240
+ def run(task)
241
+ each { |action| action.__send__ task }
242
+ end
243
+ end
244
+
245
+ end # module Actions
246
+
247
+ Options = Struct.new(:noop, :verbose, :destdir)
248
+
249
+ class PackageSpecification_1_0
250
+
251
+ TASKS = %w[config setup install test show]
252
+ # default options for translate(foo => bar)
253
+ TRANSLATE_DEFAULT_OPTIONS = { :inherit => true }
254
+
255
+ def self.declare_file_type(args, &handle_arg)
256
+ str_arr_p = lambda{|x| Array === x && x.all?{|y| String === y}}
257
+
258
+ # strict type checking --- we don't want this to be extended arbitrarily
259
+ unless args.size == 1 && Hash === args.first &&
260
+ args.first.all?{|f,r| [Proc, String, NilClass].include?(r.class) &&
261
+ (String === f || str_arr_p[f])} or
262
+ args.all?{|x| String === x || str_arr_p[x]}
263
+ raise SpecificationError,
264
+ "Unspecified semantics for the given arguments: #{args.inspect}"
265
+ end
266
+
267
+ if args.size == 1 && Hash === args.first
268
+ args.first.to_a.each do |file, rename_info|
269
+ if Array === file
270
+ # ignoring boring files
271
+ handle_arg.call(file, true, rename_info)
272
+ else
273
+ # we do want "boring" files given explicitly
274
+ handle_arg.call([file], false, rename_info)
275
+ end
276
+ end
277
+ else
278
+ args.each do |a|
279
+ if Array === a
280
+ a.each{|file| handle_arg.call(file, true, nil)}
281
+ else
282
+ handle_arg.call(a, false, nil)
283
+ end
284
+ end
285
+ end
286
+ end
287
+
288
+ #{{{ define the file tagging methods
289
+ KINDS.each { |kind|
290
+ define_method(kind) { |*args| # if this were 1.9 we could also take a block
291
+ bin_callback = lambda do |kind_, type, dest, options|
292
+ next if kind_ != :bin || type == :dir
293
+ @actions << Actions::FixShebang.new(dest, options)
294
+ end
295
+ #TODO: refactor
296
+ self.class.declare_file_type(args) do |files, ignore_p, opt_rename_info|
297
+ files.each do |file|
298
+ next if ignore_p && IGNORE_FILES.any?{|re| re.match(file)}
299
+ add_file(kind, file, opt_rename_info, &bin_callback)
300
+ end
301
+ end
302
+ }
303
+ }
304
+
305
+ def unit_test(*files)
306
+ @unit_tests.concat files.flatten
307
+ end
308
+
309
+ attr_accessor :actions, :options
310
+
311
+ def self.metadata(name)
312
+ define_method(name) { |*args|
313
+ if args.size == 1
314
+ @metadata[name] = args.first
315
+ end
316
+ @metadata[name]
317
+ }
318
+ end
319
+
320
+ metadata :name
321
+ metadata :version
322
+ metadata :author
323
+
324
+
325
+ def translate_dir(kind, dir)
326
+ replaced_dir_parts = dir.split(%r{/})
327
+ kept_dir_parts = []
328
+ loop do
329
+ replaced_path = replaced_dir_parts.join("/")
330
+ target, options = @translate[kind][replaced_path]
331
+ options ||= TRANSLATE_DEFAULT_OPTIONS
332
+ if target && (replaced_path == dir || options[:inherit])
333
+ dir = (target != '' ? File.join(target, *kept_dir_parts) :
334
+ File.join(*kept_dir_parts))
335
+ break
336
+ end
337
+ break if replaced_dir_parts.empty?
338
+ kept_dir_parts.unshift replaced_dir_parts.pop
339
+ end
340
+ dir
341
+ end
342
+
343
+ def add_file(kind, filename, new_filename_info, &callback)
344
+ #TODO: refactor!!!
345
+ if File.directory? filename #XXX setup.rb and rpa-base defined File.dir?
346
+ # to cope with some win32 issue
347
+ dir = filename.sub(/\A\.\//, "").sub(/\/\z/, "")
348
+ dest = File.join(@prefixes[kind], @dirs[kind], translate_dir(kind, dir))
349
+ @actions << Actions::MkDir.new(dest, @options)
350
+ callback.call(kind, :dir, dest, @options) if block_given?
351
+ else
352
+ if new_filename_info
353
+ case new_filename_info
354
+ when Proc
355
+ dest_name = new_filename_info.call(filename.dup)
356
+ else
357
+ dest_name = new_filename_info.dup
358
+ end
359
+ else
360
+ dest_name = filename.dup
361
+ end
362
+
363
+ dirname = File.dirname(dest_name)
364
+ dirname = "" if dirname == "."
365
+ dest_name = File.join(translate_dir(kind, dirname), File.basename(dest_name))
366
+
367
+ dest = File.join(@prefixes[kind], @dirs[kind], dest_name)
368
+ @actions << Actions::InstallFile.new(filename, dest, MODES[kind], @options)
369
+ callback.call(kind, :file, dest, @options) if block_given?
370
+ end
371
+ end
372
+
373
+ def initialize(prefixes = nil, dirs = nil)
374
+ @prefix = Config::CONFIG["prefix"].gsub(/\A\//, '')
375
+ @translate = {}
376
+ @prefixes = (prefixes || {}).dup
377
+ KINDS.each { |kind|
378
+ @prefixes[kind] = @prefix unless prefixes
379
+ @translate[kind] = {}
380
+ }
381
+
382
+ @dirs = (dirs || {}).dup
383
+ @dirs.update SITE_DIRS unless dirs
384
+
385
+ @actions = Actions::ActionList.new
386
+
387
+ @metadata = {}
388
+ @unit_tests = []
389
+
390
+ @options = Options.new
391
+ @options.verbose = true
392
+ @options.noop = false # XXX for testing
393
+ @options.destdir = ''
394
+
395
+ @tasks = []
396
+ end
397
+
398
+ def aoki
399
+ (KINDS - [:ext]).each { |kind|
400
+ translate(kind, kind.to_s => "", :inherit => true)
401
+ __send__ kind, Dir["#{kind}/**/*"]
402
+ }
403
+ translate(:ext, "ext/*" => "", :inherit => true)
404
+ ext Dir["ext/**/*.#{Config::CONFIG['DLEXT']}"]
405
+ end
406
+
407
+ def install
408
+ puts "Installing #{name || "unknown package"} #{version}..." if options.verbose
409
+
410
+ actions.uniq!
411
+ actions.sort!
412
+ actions.directories!(options)
413
+
414
+ #pp self
415
+
416
+ actions.run :install
417
+ end
418
+
419
+ def test
420
+ unless @unit_tests.empty?
421
+ puts "Testing #{name || "unknown package"} #{version}..." if options.verbose
422
+ require 'test/unit'
423
+ unless options.noop
424
+ t = Test::Unit::AutoRunner.new(true)
425
+ t.process_args(@unit_tests)
426
+ t.run
427
+ end
428
+ end
429
+ end
430
+
431
+ def config
432
+ File.open("config.save", "w") { |f|
433
+ YAML.dump({:prefixes => @prefixes, :dirs => @dirs}, f)
434
+ }
435
+ end
436
+
437
+ def show
438
+ KINDS.each { |kind|
439
+ puts "#{kind}\t#{File.join(options.destdir, @prefixes[kind], @dirs[kind])}"
440
+ }
441
+ end
442
+
443
+ def translate(kind, additional_translations)
444
+ default_opts = TRANSLATE_DEFAULT_OPTIONS.dup
445
+ key_val_pairs = additional_translations.to_a
446
+ option_pairs = key_val_pairs.select{|(k,v)| Symbol === k}
447
+ default_opts.update(Hash[*option_pairs.flatten])
448
+
449
+ (key_val_pairs - option_pairs).each do |key, val|
450
+ add_translation(kind, key, val, default_opts)
451
+ end
452
+ end
453
+
454
+ def add_translation(kind, src, dest, options)
455
+ if is_glob?(src)
456
+ dirs = expand_dir_glob(src)
457
+ else
458
+ dirs = [src]
459
+ end
460
+ dirs.each do |dirname|
461
+ dirname = dirname.sub(%r{\A\./}, "").sub(%r{/\z}, "")
462
+ @translate[kind].update({dirname => [dest, options]})
463
+ end
464
+ end
465
+
466
+ def is_glob?(x)
467
+ /(^|[^\\])[*?{\[]/.match(x)
468
+ end
469
+
470
+ def expand_dir_glob(src)
471
+ Dir[src].select{|x| File.directory?(x)}
472
+ end
473
+
474
+ def clean_path(path)
475
+ path.gsub(/\A\//, '').gsub(/\/+\Z/, '').squeeze("/")
476
+ end
477
+
478
+ def parse_command_line
479
+ opts = OptionParser.new(nil, 24, ' ') { |opts|
480
+ opts.banner = "Usage: setup.rb [options] [task]"
481
+
482
+ opts.separator ""
483
+ opts.separator "Tasks:"
484
+ opts.separator " config configures paths"
485
+ opts.separator " show shows paths"
486
+ opts.separator " setup compiles ruby extentions and others XXX"
487
+ opts.separator " install installs files"
488
+ opts.separator " test runs unit tests"
489
+
490
+
491
+ opts.separator ""
492
+ opts.separator "Specific options:"
493
+
494
+ opts.on "--prefix=PREFIX",
495
+ "path prefix of target environment [#@prefix]" do |prefix|
496
+ @prefix.replace clean_path(prefix) # Shared!
497
+ end
498
+
499
+ opts.separator ""
500
+
501
+ KINDS.each { |kind|
502
+ opts.on "--#{kind}prefix=PREFIX",
503
+ "path prefix for #{kind} files [#{@prefixes[kind]}]" do |prefix|
504
+ @prefixes[kind] = clean_path(prefix)
505
+ end
506
+ }
507
+
508
+ opts.separator ""
509
+
510
+ KINDS.each { |kind|
511
+ opts.on "--#{kind}dir=PREFIX",
512
+ "directory for #{kind} files [#{@dirs[kind]}]" do |prefix|
513
+ @dirs[kind] = clean_path(prefix)
514
+ end
515
+ }
516
+
517
+ opts.separator ""
518
+
519
+ KINDS.each { |kind|
520
+ opts.on "--#{kind}=PREFIX",
521
+ "absolute directory for #{kind} files [#{File.join(@prefixes[kind], @dirs[kind])}]" do |prefix|
522
+ @prefixes[kind] = clean_path(prefix)
523
+ end
524
+ }
525
+
526
+ opts.separator ""
527
+ opts.separator "Predefined path configurations:"
528
+ opts.on "--site", "install into site-local directories (default)" do
529
+ @dirs.update SITE_DIRS
530
+ end
531
+
532
+ opts.on "--vendor", "install into distribution directories (for packagers)" do
533
+ @dirs.update VENDOR_DIRS
534
+ end
535
+
536
+ opts.separator ""
537
+ opts.separator "General options:"
538
+
539
+ opts.on "--destdir=DESTDIR",
540
+ "install all files relative to DESTDIR (/)" do |destdir|
541
+ @options.destdir = destdir
542
+ end
543
+
544
+ opts.on "--dry-run", "only display what to do if given [#{@options.noop}]" do
545
+ @options.noop = true
546
+ end
547
+
548
+ opts.on "--no-harm", "only display what to do if given" do
549
+ @options.noop = true
550
+ end
551
+
552
+ opts.on "--[no-]verbose", "output messages verbosely [#{@options.verbose}]" do |verbose|
553
+ @options.verbose = verbose
554
+ end
555
+
556
+ opts.on_tail("-h", "--help", "Show this message") do
557
+ puts opts
558
+ exit
559
+ end
560
+ }
561
+
562
+ opts.parse! ARGV
563
+
564
+ if (ARGV - TASKS).empty? # Only existing tasks?
565
+ @tasks = ARGV
566
+ @tasks = ["install"] if @tasks.empty?
567
+ else
568
+ abort "Unknown task(s) #{(ARGV-TASKS).join ", "}."
569
+ end
570
+ end
571
+
572
+ def run_tasks
573
+ @tasks.each { |task| __send__ task }
574
+ end
575
+ end
576
+
577
+ end # module Package
578
+
579
+ #XXX incomplete setup.rb support for the hooks
580
+ require 'rbconfig'
581
+ def config(x)
582
+ Config::CONFIG[x]
583
+ end
584
+
585
+ #{{{ small example
586
+ if $0 == __FILE__
587
+ Package.setup("1.0") {
588
+ name "Crypt::ISAAC"
589
+
590
+ lib "crypt/ISAAC.rb"
591
+
592
+ unit_test Dir["test/TC*.rb"]
593
+ }
594
+ end
595
+
596
+ # vim: sw=2 sts=2 et ts=8
@@ -0,0 +1,76 @@
1
+ require 'test/unit'
2
+ if ARGV[0] == 'local'
3
+ begin
4
+ require '../crypt/ISAAC.rb'
5
+ rescue Exception
6
+ require './crypt/ISAAC.rb'
7
+ end
8
+ else
9
+ begin
10
+ require 'crypt/ISAACC'
11
+ rescue Exception
12
+ require './crypt/ISAAC.rb'
13
+ end
14
+ end
15
+
16
+ class TC_ISAAC < Test::Unit::TestCase
17
+ def setup
18
+ assert_nothing_raised("Failed to create a Crypt::ISAAC object.") do
19
+ @generator = Crypt::ISAAC.new
20
+ end
21
+ end
22
+
23
+ def testKind
24
+ assert_kind_of(Crypt::ISAAC,@generator,"The created object is not a Crypt::ISAAC or subclass thereof.")
25
+ end
26
+
27
+ def testInteger
28
+ assert_nothing_raised("Failed while generating an integer random number.") do
29
+ mynum = @generator.rand(1000000)
30
+ assert_kind_of(Integer,mynum,"The generator failed to return an integer number in response to @generator.rand(1000000).")
31
+ assert((mynum >= 0),"The generator returned a number that is less than 0 (#{mynum}).")
32
+ assert((mynum < 1000000),"The generator returned a number that is greater than or equal to 1000000 (#{mynum}).")
33
+ end
34
+ end
35
+
36
+ def testFloat
37
+ assert_nothing_raised("Failed while generating a floating point random number.") do
38
+ mynum = @generator.rand()
39
+ assert_kind_of(Float,mynum,"The generator failed to return a floating point number in response to @generator.rand().")
40
+ assert((mynum >= 0),"The generator returned a number that is less than 0 (#{mynum}).")
41
+ assert((mynum < 1),"The generator returned a number that is greater than or equal to 1 (#{mynum}).")
42
+ end
43
+ end
44
+
45
+ def testIterations
46
+ puts
47
+ count = 0
48
+ assert_nothing_raised("Failed on iteration #{count} while trying to generate 100000 random numbers.") do
49
+ 100000.times do
50
+ count += 1
51
+ x = @generator.rand(4294967295)
52
+ print [x].pack('V').unpack('H8') if count % 1000 == 0
53
+ if (count % 7000) == 0
54
+ print "\n"
55
+ else
56
+ print " " if count % 1000 == 0
57
+ end
58
+ end
59
+ puts "\n100000 numbers generated"
60
+ end
61
+ end
62
+
63
+ def testDualStreams
64
+ g1 = nil
65
+ g2 = nil
66
+ assert_nothing_raised("Failed to pull numbers from two independent streams.") do
67
+ g1 = Crypt::ISAAC.new
68
+ g2 = Crypt::ISAAC.new
69
+ assert((g1 != g2),"The generators are the same. This should not happen.")
70
+ 1000.times do
71
+ g1.rand(4294967295)
72
+ g2.rand(4294967295)
73
+ end
74
+ end
75
+ end
76
+ end