Skip to content

Commit 03e34e0

Browse files
committed
ruby: inline expectations tests for CryptographicOperation concept
1 parent 4752c45 commit 03e34e0

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

ruby/ql/test/library-tests/concepts/CryptographicOperation.expected

Whitespace-only changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import ruby
2+
import codeql.ruby.Concepts
3+
import TestUtilities.InlineExpectationsTest
4+
5+
class CryptographicOperationTest extends InlineExpectationsTest {
6+
CryptographicOperationTest() { this = "CryptographicOperationTest" }
7+
8+
override string getARelevantTag() {
9+
result in [
10+
"CryptographicOperation", "CryptographicOperationInput", "CryptographicOperationAlgorithm",
11+
"CryptographicOperationBlockMode"
12+
]
13+
}
14+
15+
override predicate hasActualResult(Location location, string element, string tag, string value) {
16+
exists(location.getFile().getRelativePath()) and
17+
exists(Cryptography::CryptographicOperation cryptoOperation |
18+
location = cryptoOperation.getLocation() and
19+
(
20+
element = cryptoOperation.toString() and
21+
value = "" and
22+
tag = "CryptographicOperation"
23+
or
24+
element = cryptoOperation.toString() and
25+
value = cryptoOperation.getAlgorithm().getName() and
26+
tag = "CryptographicOperationAlgorithm"
27+
or
28+
element = cryptoOperation.toString() and
29+
value = cryptoOperation.getBlockMode() and
30+
tag = "CryptographicOperationBlockMode"
31+
)
32+
)
33+
}
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'openssl'
2+
3+
strong = OpenSSL::Cipher.new 'AES-128-CBC' # $ CryptographicOperation CryptographicOperationAlgorithm=AES CryptographicOperationBlockMode=CBC
4+
5+
weak_algorithm = OpenSSL::Cipher::DES.new # $ CryptographicOperation CryptographicOperationAlgorithm=DES CryptographicOperationBlockMode=CBC
6+
7+
weak_block_mode = OpenSSL::Cipher::AES.new(128, :ecb) # $ CryptographicOperation CryptographicOperationAlgorithm=AES CryptographicOperationBlockMode=ECB

0 commit comments

Comments
 (0)