add generic tests for features

This commit is contained in:
Esben Sparre Andreasen
2022-03-30 12:02:50 +02:00
committed by Stephan Brandauer
parent f3cdb12dcf
commit 41b35eaa49
12 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
| calleeApiName |
| enclosingFunctionBody |
| enclosingFunctionName |

View File

@@ -0,0 +1,8 @@
import javascript
import experimental.adaptivethreatmodeling.EndpointFeatures
import TestUtil
// every feature must produce a value for at least one endpoint, otherwise the feature is completely broken, or a relevant test example is missing
from EndpointFeature feature
where forall(Endpoint endpoint | not exists(feature.getValue(endpoint)))
select feature.getName()

View File

@@ -0,0 +1,29 @@
| test.js:2:7:2:14 | endpoint | ParameterAccessPathSimpleFromArgumentTraversal | 0 |
| test.js:2:7:2:14 | endpoint | argumentIndex | 0 |
| test.js:2:7:2:14 | endpoint | calleeAccessPath | |
| test.js:2:7:2:14 | endpoint | calleeAccessPathSimpleFromArgumentTraversal | f |
| test.js:2:7:2:14 | endpoint | calleeAccessPathWithStructuralInfo | |
| test.js:2:7:2:14 | endpoint | calleeName | f |
| test.js:3:11:3:18 | endpoint | ParameterAccessPathSimpleFromArgumentTraversal | 0.p |
| test.js:3:11:3:18 | endpoint | calleeAccessPath | |
| test.js:3:11:3:18 | endpoint | calleeAccessPathSimpleFromArgumentTraversal | f |
| test.js:3:11:3:18 | endpoint | calleeAccessPathWithStructuralInfo | |
| test.js:4:15:4:22 | endpoint | ParameterAccessPathSimpleFromArgumentTraversal | 0.p.q |
| test.js:4:15:4:22 | endpoint | calleeAccessPath | |
| test.js:4:15:4:22 | endpoint | calleeAccessPathSimpleFromArgumentTraversal | f |
| test.js:4:15:4:22 | endpoint | calleeAccessPathWithStructuralInfo | |
| test.js:5:9:5:16 | endpoint | ParameterAccessPathSimpleFromArgumentTraversal | 0 |
| test.js:5:9:5:16 | endpoint | argumentIndex | 0 |
| test.js:5:9:5:16 | endpoint | calleeAccessPath | |
| test.js:5:9:5:16 | endpoint | calleeAccessPathSimpleFromArgumentTraversal | o.m |
| test.js:5:9:5:16 | endpoint | calleeAccessPathWithStructuralInfo | |
| test.js:5:9:5:16 | endpoint | calleeName | m |
| test.js:5:9:5:16 | endpoint | receiverName | o |
| test.js:6:13:6:20 | endpoint | ParameterAccessPathSimpleFromArgumentTraversal | 0.p |
| test.js:6:13:6:20 | endpoint | calleeAccessPath | |
| test.js:6:13:6:20 | endpoint | calleeAccessPathSimpleFromArgumentTraversal | o.m |
| test.js:6:13:6:20 | endpoint | calleeAccessPathWithStructuralInfo | |
| test.js:7:17:7:24 | endpoint | ParameterAccessPathSimpleFromArgumentTraversal | 0.p.q |
| test.js:7:17:7:24 | endpoint | calleeAccessPath | |
| test.js:7:17:7:24 | endpoint | calleeAccessPathSimpleFromArgumentTraversal | o.m |
| test.js:7:17:7:24 | endpoint | calleeAccessPathWithStructuralInfo | |

View File

@@ -0,0 +1,7 @@
import javascript
import experimental.adaptivethreatmodeling.EndpointFeatures
import TestUtil
// detailed output for the nearby tests
from Endpoint endpoint, EndpointFeature feature
select endpoint, feature.getName(), feature.getValue(endpoint)

View File

@@ -0,0 +1,8 @@
import javascript
import experimental.adaptivethreatmodeling.EndpointFeatures
import TestUtil
// every endpoint should have at least one feature value, otherwise the test source is likely malformed
from Endpoint endpoint
where not exists(EndpointFeature f | exists(f.getValue(endpoint)))
select endpoint

View File

@@ -0,0 +1,8 @@
import javascript
import experimental.adaptivethreatmodeling.EndpointFeatures
import TestUtil
// every feature must produce a single value for each endpoint that it computes a value for, otherwise the ML model will be confused(?)
from Endpoint endpoint, EndpointFeature feature, int arity
where arity = count(feature.getValue(endpoint)) and arity > 1
select endpoint, feature.getName(), arity

View File

@@ -0,0 +1,31 @@
| test.js:2:7:2:14 | endpoint | calleeApiName |
| test.js:2:7:2:14 | endpoint | enclosingFunctionBody |
| test.js:2:7:2:14 | endpoint | enclosingFunctionName |
| test.js:2:7:2:14 | endpoint | receiverName |
| test.js:3:11:3:18 | endpoint | argumentIndex |
| test.js:3:11:3:18 | endpoint | calleeApiName |
| test.js:3:11:3:18 | endpoint | calleeName |
| test.js:3:11:3:18 | endpoint | enclosingFunctionBody |
| test.js:3:11:3:18 | endpoint | enclosingFunctionName |
| test.js:3:11:3:18 | endpoint | receiverName |
| test.js:4:15:4:22 | endpoint | argumentIndex |
| test.js:4:15:4:22 | endpoint | calleeApiName |
| test.js:4:15:4:22 | endpoint | calleeName |
| test.js:4:15:4:22 | endpoint | enclosingFunctionBody |
| test.js:4:15:4:22 | endpoint | enclosingFunctionName |
| test.js:4:15:4:22 | endpoint | receiverName |
| test.js:5:9:5:16 | endpoint | calleeApiName |
| test.js:5:9:5:16 | endpoint | enclosingFunctionBody |
| test.js:5:9:5:16 | endpoint | enclosingFunctionName |
| test.js:6:13:6:20 | endpoint | argumentIndex |
| test.js:6:13:6:20 | endpoint | calleeApiName |
| test.js:6:13:6:20 | endpoint | calleeName |
| test.js:6:13:6:20 | endpoint | enclosingFunctionBody |
| test.js:6:13:6:20 | endpoint | enclosingFunctionName |
| test.js:6:13:6:20 | endpoint | receiverName |
| test.js:7:17:7:24 | endpoint | argumentIndex |
| test.js:7:17:7:24 | endpoint | calleeApiName |
| test.js:7:17:7:24 | endpoint | calleeName |
| test.js:7:17:7:24 | endpoint | enclosingFunctionBody |
| test.js:7:17:7:24 | endpoint | enclosingFunctionName |
| test.js:7:17:7:24 | endpoint | receiverName |

View File

@@ -0,0 +1,8 @@
import javascript
import experimental.adaptivethreatmodeling.EndpointFeatures
import TestUtil
// every feature should produce a value for all endpoints
from EndpointFeature feature, Endpoint endpoint
where not exists(feature.getValue(endpoint))
select endpoint, feature.getName()

View File

@@ -0,0 +1,5 @@
import javascript
class Endpoint extends DataFlow::Node {
Endpoint() { this.asExpr().(VarAccess).getName() = "endpoint" }
}

View File

@@ -0,0 +1,9 @@
(function(){
f(endpoint);
f({p: endpoint})
f({p: {q: endpoint}})
o.m(endpoint);
o.m({p: endpoint})
o.m({p: {q: endpoint}})
});