1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
# -*- tcl -*-
# md5crypt.test: tests for the md5crypt commands
#
# This file contains a collection of tests for one or more of the Tcllib
# commands. Sourcing this file into Tcl runs the tests and generates
# output for errors. No output means no errors were found.
#
# Copyright (C) 2003 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# RCS: @(#) $Id: md5crypt.test,v 1.5 2004/02/14 05:59:21 andreas_kupries Exp $
# -------------------------------------------------------------------------
# Initialize the test package
#
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
# -------------------------------------------------------------------------
# Ensure we test _this_ local copy and one installed somewhere else.
#
package forget md5crypt
catch {namespace delete ::md5crypt}
if {[catch {source [file join [file dirname [info script]] md5crypt.tcl]} msg]} {
puts "skipped [file tail [info script]]: $msg"
return
}
# -------------------------------------------------------------------------
# Setup any constraints
#
# Set this true if we have the critcl version.
if {[package vsatisfies [package provide tcltest] 2.0]} {
::tcltest::testConstraint md5crypt_c \
[expr {[info command ::md5crypt::md5crypt_c] != {}}]
} else {
set ::tcltest::testConstraints(md5crypt_c) \
[expr {[info command ::md5crypt::md5crypt_c] != {}}]
}
# -------------------------------------------------------------------------
# Now the package specific tests....
# -------------------------------------------------------------------------
if {[info command ::md5crypt::md5crypt_c] != {}} {
puts "- md5crypt [package present md5crypt] (critcl based)"
} else {
puts "- md5crypt [package present md5crypt] (pure Tcl)"
}
# -------------------------------------------------------------------------
test md5crypt-1.0 {md5crypt basic usage} {
catch {::md5crypt::md5crypt} result
string match [tcltest::wrongNumArgs {*} {pw salt} 0] $result
} 1
test md5crypt-1.1 {md5crypt basic usage} {
catch {::md5crypt::md5crypt pw} result
string match [tcltest::wrongNumArgs {*} {pw salt} 1] $result
} 1
test md5crypt-1.2 {md5crypt basic usage} {
catch {::md5crypt::md5crypt pw salt other} result
string match [tcltest::tooManyArgs {*} {pw salt}] $result
} 1
# -------------------------------------------------------------------------
foreach {n salt passwd expected} {
1 {} a {$1$$Ij31LCAysPM23KuPlm1wA/}
2 {a} a {$1$a$44cUw6Nm5bX0muHWNIwub0}
3 {aa} a {$1$aa$aM/8fu5RTEKSCJWsk9qH.0}
4 {aaa} a {$1$aaa$SCk4CXyogLtcfwl2VqfSF0}
5 {aaaa} a {$1$aaaa$tjZedp/Ch2UpwkJdEKLPm.}
6 {aaaaa} a {$1$aaaaa$iVkHUcCwuXWk4NaYTbyUa/}
7 {aaaaaa} a {$1$aaaaaa$MUMWPbGfzrHFCNm7ZHg31.}
8 {aaaaaaa} a {$1$aaaaaaa$4OzJTk7W1gmppy.1Lu4nr.}
9 {aaaaaaaa} a {$1$aaaaaaaa$S270EsVIz5M8Y9/k4SSEf.}
10 {aaaaaaaaa} a {$1$aaaaaaaa$S270EsVIz5M8Y9/k4SSEf.}
12 {a$aaaaaaa} a {$1$a$44cUw6Nm5bX0muHWNIwub0}
13 {$1$a$junk} a {$1$a$44cUw6Nm5bX0muHWNIwub0}
} {
test md5passwd-2.${n} [list md5crypt salt check \"$salt\"] {
::md5crypt::md5crypt $passwd $salt
} $expected
# If the C code is loaded, then we have tested that so now check the
# pure-tcl implementation as well.
test md5passwd-3.${n}_tcl [list md5crypt salt check \"$salt\"] \
{md5crypt_c} {
::md5crypt::md5crypt_tcl {$1$} $passwd $salt
} $expected
}
# -------------------------------------------------------------------------
foreach {n salt passwd expected} [list \
1 {a} {} {$1$a$8CfZSfErbeskipdhZHtvu.} \
2 {a} {a} {$1$a$44cUw6Nm5bX0muHWNIwub0} \
3 {a} [string repeat a 100] {$1$a$vTAcWEblAgdUlX6KBz0NM.} \
4 {a} [string repeat a 200] {$1$a$kC.K4D6mvUznpkjWJK8Tm0} \
5 {a} [string repeat a 400] {$1$a$nBvNVTsAryOnHlW7L/gzf/} \
6 {a} [string repeat a 1000] {$1$a$yhNnTV4IKHbl8oEB/eJaj0} \
] {
test md5passwd-4.${n} {md5crypt check passwd} {
::md5crypt::md5crypt $passwd $salt
} $expected
# If the C code is loaded, then we have tested that so now check the
# pure-tcl implementation as well.
test md5passwd-5.${n}_tcl {md5crypt (pure-Tcl) check passwd} {md5crypt_c} {
::md5crypt::md5crypt_tcl {$1$} $passwd $salt
} $expected
}
# -------------------------------------------------------------------------
foreach {n salt passwd expected} [list \
1 {883.....} {a} {$apr1$883.....$wCU4E7Fv9tHAzFEm5D.mp/} \
2 {XA3.....} {a} {$apr1$XA3.....$kp5j/oX/OCrpKdKhmUqTu1} \
] {
test md5passwd-6.${n} {aprcrypt check passwd} {
::md5crypt::aprcrypt $passwd $salt
} $expected
# If the C code is loaded, then we have tested that so now check the
# pure-tcl implementation as well.
test md5passwd-7.${n}_tcl {aprcrypt (pure-Tcl) check passwd} {md5crypt_c} {
::md5crypt::md5crypt_tcl {$apr1$} $passwd $salt
} $expected
}
# -------------------------------------------------------------------------
::tcltest::cleanupTests
# -------------------------------------------------------------------------
# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End:
|