/
SecurityHelpersSpec.scala
98 lines (85 loc) · 3.45 KB
/
SecurityHelpersSpec.scala
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
/*
* Copyright 2006-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb
package util
import org.specs2.mutable.Specification
import SecurityHelpers._
/**
* Systems under specification for SecurityHelpers.
*/
object SecurityHelpersSpec extends Specification {
"SecurityHelpers Specification".title
"Security Helpers" should {
"Parse XML with nasty entity references" in {
secureXML.loadString("""<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<foo>&xxe;</foo>"""
) must_== <foo></foo>
}
"Parse XML with deal with nice entity references" in {
secureXML.loadString("""<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<foo>&</foo>
""").toString must_== "<foo>&</foo>"
}
"provide a randomLong method returning a random Long modulo a number" in {
randomLong(7L) must be_<(7L)
}
"provide a randomInt method returning a random Int modulo a number" in {
randomInt(7) must be_<(7)
}
"provide a shouldShow function always returning true only a given percentage of time, expressed as a Int between 0 and 100" in {
shouldShow(100) must beTrue
shouldShow(0) must beFalse
}
"provide a shouldShow function always returning true only a given percentage of time, expressed as a Double between 0 and 1.0" in {
shouldShow(1.0) must beTrue
shouldShow(0.0) must beFalse
}
/*
"provide makeBlowfishKey, blowfishEncrypt, blowfishDecrypt functions to encrypt/decrypt Strings with Blowfish keys" in {
val key = makeBlowfishKey
val encrypted = blowfishEncrypt("hello world", key)
encrypted must_!= "hello world"
blowfishDecrypt(encrypted, key) must_== "hello world"
}
*/
"provide a md5 function to create a md5 digest from a string" in {
md5("hello") must_== "XUFAKrxLKna5cZ2REBfFkg=="
md5("hello") must_!= md5("hell0")
}
"provide a hash function to create a SHA digest from a string" in {
hash("hello") must_== "qvTGHdzF6KLavt4PO0gs2a6pQ00="
hash("hello") must_!= hash("hell0")
}
"provide a hash256 function to create a SHA-256 digest from a string" in {
hash256("hello") must_== "LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ="
hash256("hello") must_!= hash256("hell0")
}
"provide a hex encoded SHA hash function" in {
hexDigest("hello".getBytes) must_== "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"
hexDigest("hello".getBytes) must_!= hexDigest("hell0".getBytes)
}
"provide a hex encoded SHA-256 hash function" in {
hexDigest256("hello".getBytes) must_== "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
hexDigest256("hello".getBytes) must_!= hexDigest256("hell0".getBytes)
}
}
}