diff --git a/ql/lib/codeql/bicep/ast/Expr.qll b/ql/lib/codeql/bicep/ast/Expr.qll index d76d8d5..b8063b6 100644 --- a/ql/lib/codeql/bicep/ast/Expr.qll +++ b/ql/lib/codeql/bicep/ast/Expr.qll @@ -16,7 +16,6 @@ private import internal.NullableType private import internal.ParenthesizedExpression private import internal.PrimaryExpression private import internal.ResourceExpression -private import internal.SubscriptExpression private import internal.TernaryExpression private import internal.UnaryExpression private import Idents @@ -30,12 +29,37 @@ final class Expr extends AstNode instanceof ExprImpl { } /** * A AssignmentExpression expression in the AST. */ -final class AssignmentExpression extends Expr instanceof AssignmentExpressionImpl { } +class AssignmentExpression extends Expr instanceof AssignmentExpressionImpl { + /** + * Gets the left operand of the assignment expression. + */ + Expr getLeft() { result = AssignmentExpressionImpl.super.getLeft() } + + /** + * Gets the right operand of the assignment expression. + */ + Expr getRight() { result = AssignmentExpressionImpl.super.getRight() } +} /** * A BinaryExpression expression in the AST. */ -final class BinaryExpression extends Expr instanceof BinaryExpressionImpl { } +class BinaryExpression extends Expr instanceof BinaryExpressionImpl { + /** + * Gets the left operand of the binary expression. + */ + Expr getLeft() { result = BinaryExpressionImpl.super.getLeft() } + + /** + * Gets the right operand of the binary expression. + */ + Expr getRight() { result = BinaryExpressionImpl.super.getRight() } + + /** + * Gets the operator of the binary expression. + */ + string getOperator() { result = BinaryExpressionImpl.super.getOperator() } +} /** * A Expression expression in the AST. @@ -45,7 +69,18 @@ final class Expression extends Expr instanceof ExpressionImpl { } /** * A Interpolation literal in the AST. */ -final class Interpolation extends Expr instanceof InterpolationImpl { } +final class Interpolation extends Expr instanceof InterpolationImpl { + /** + * Gets the expression contained within the interpolation. + */ + Expr getExpression() { + result = InterpolationImpl.super.getExpression() + } + + string getValue() { + result = "${" + this.getExpression().toString() + "}" + } +} /** * A LambdaExpression expression in the AST. @@ -69,9 +104,7 @@ class MemberExpression extends Expr instanceof MemberExpressionImpl { /** * Gets the full name of the member expression, which includes the namespace and the member name. */ - string getFullName() { - result = this.getNamespace().getName() + "." + this.getName().getName() - } + string getFullName() { result = this.getNamespace().getName() + "." + this.getName().getName() } } /** @@ -87,7 +120,21 @@ final class NullableType extends Expr instanceof NullableTypeImpl { } /** * A ParenthesizedExpression expression in the AST. */ -final class ParenthesizedExpression extends Expr instanceof ParenthesizedExpressionImpl { } +class ParenthesizedExpression extends Expr instanceof ParenthesizedExpressionImpl { + /** + * Gets the expression contained within the parentheses. + */ + Expr getExpression(int index) { + result = ParenthesizedExpressionImpl.super.getExpression(index) + } + + /** + * Get the expressions contained within the parentheses. + */ + Expr getExpressions() { + result = ParenthesizedExpressionImpl.super.getExpressions() + } +} /** * A PrimaryExpression expression in the AST. @@ -99,11 +146,6 @@ final class PrimaryExpression extends Expr instanceof PrimaryExpressionImpl { } */ final class ResourceExpression extends Expr instanceof ResourceExpressionImpl { } -/** - * A SubscriptExpression expression in the AST. - */ -final class SubscriptExpression extends Expr instanceof SubscriptExpressionImpl { } - /** * A TernaryExpression expression in the AST. */ diff --git a/ql/lib/codeql/bicep/ast/Literals.qll b/ql/lib/codeql/bicep/ast/Literals.qll index 75e9371..5929d24 100644 --- a/ql/lib/codeql/bicep/ast/Literals.qll +++ b/ql/lib/codeql/bicep/ast/Literals.qll @@ -4,6 +4,8 @@ private import AstNodes private import Expr +private import Idents +private import Variables private import internal.AstNodes private import internal.TreeSitter private import internal.Literals @@ -14,6 +16,7 @@ private import internal.NullableReturnType private import internal.Number private import internal.String private import internal.StringContent +private import internal.SubscriptExpression /** * A literal in the AST. @@ -29,6 +32,35 @@ class Array extends Literals instanceof ArrayImpl { Expr getElement(int index) { result = ArrayImpl.super.getElement(index) } } +/** + * A SubscriptExpression expression in the AST. + */ +class SubscriptExpression extends Expr instanceof SubscriptExpressionImpl { + /** + * Gets the index of the subscript expression. + */ + Expr getIndex() { result = SubscriptExpressionImpl.super.getIndex() } + + /** + * Gets the object of the subscript expression. + */ + Idents getIdentifier() { result = SubscriptExpressionImpl.super.getObject() } + + /** + * Gets the array that this subscript expression is indexing into. + * This is equivalent to the variable declaration that contains the + * subscript expression. + */ + Array getArray() { + exists(VariableDeclaration variable | + variable.getEnclosingCfgScope() = this.getEnclosingCfgScope() and + variable.getIdentifier().getName() = this.getIdentifier().getName() + | + result = variable.getInitializer() + ) + } +} + /** * A Boolean unknown AST node. */ @@ -66,16 +98,33 @@ class Number extends Literals instanceof NumberImpl { int getValue() { result = NumberImpl.super.getValue().toInt() } } +class String = StringLiteral; + /** * A String literal in the AST. */ class StringLiteral extends Literals instanceof StringImpl { + /** + * Gets the value of the string literal. + */ string getValue() { - exists(StringContentLiteral content | - content = this.getAChild() and - result = content.getValue() - ) + result = + concat(int index, string output | + exists(StringContentLiteral content | + content = StringImpl.super.getChild(index) and + output = content.getValue() + ) + or + exists(Interpolation interpolation | + interpolation = StringImpl.super.getChild(index) and + output = interpolation.getValue() + ) + | + output order by index + ) } + + Interpolation getInterpolation(int index) { result = StringImpl.super.getChild(index) } } /** diff --git a/ql/lib/codeql/bicep/ast/Misc.qll b/ql/lib/codeql/bicep/ast/Misc.qll index 2741699..6c31e2b 100644 --- a/ql/lib/codeql/bicep/ast/Misc.qll +++ b/ql/lib/codeql/bicep/ast/Misc.qll @@ -1,5 +1,4 @@ private import AstNodes - private import internal.Array private import internal.ArrayType private import internal.Boolean @@ -28,14 +27,12 @@ private import internal.Type private import internal.TypeArguments private import internal.TypeDeclaration private import internal.UnionType -private import internal.VariableDeclaration /** * A ArrayType unknown AST node. */ class ArrayType extends AstNode instanceof ArrayTypeImpl { } - /** * A CompatibleIdentifier unknown AST node. */ @@ -101,13 +98,11 @@ class ModuleDeclaration extends AstNode instanceof ModuleDeclarationImpl { } */ class NegatedType extends AstNode instanceof NegatedTypeImpl { } - /** * A ParameterizedType unknown AST node. */ class ParameterizedType extends AstNode instanceof ParameterizedTypeImpl { } - /** * A ParenthesizedType unknown AST node. */ @@ -132,12 +127,10 @@ class TestBlock extends AstNode instanceof TestBlockImpl { } * A Type unknown AST node. */ class Type extends AstNode instanceof TypeImpl { - /** - * Returns the type of this AST node. - */ - string getType() { - result = TypeImpl.super.getType() - } + /** + * Returns the type of this AST node. + */ + string getType() { result = TypeImpl.super.getType() } } /** @@ -154,9 +147,3 @@ class TypeDeclaration extends AstNode instanceof TypeDeclarationImpl { } * A UnionType unknown AST node. */ class UnionType extends AstNode instanceof UnionTypeImpl { } - - -/** - * A VariableDeclaration unknown AST node. - */ -class VariableDeclaration extends AstNode instanceof VariableDeclarationImpl { } diff --git a/ql/lib/codeql/bicep/ast/Stmts.qll b/ql/lib/codeql/bicep/ast/Stmts.qll index ca37d16..482c258 100644 --- a/ql/lib/codeql/bicep/ast/Stmts.qll +++ b/ql/lib/codeql/bicep/ast/Stmts.qll @@ -50,7 +50,13 @@ final class ForStatementStmt extends Stmts instanceof ForStatementImpl { } /** * A IfStatement statement */ -final class IfStatementStmt extends Stmts instanceof IfStatementImpl { } +class IfStatement extends Stmts instanceof IfStatementImpl { + /** Gets the condition of the if statement. */ + Expr getCondition() { result = IfStatementImpl.super.getCondition() } + + /** Gets the body of the if statement. */ + Expr getBody() { result = IfStatementImpl.super.getBody() } +} /** * A ImportStatement statement diff --git a/ql/lib/codeql/bicep/ast/Variables.qll b/ql/lib/codeql/bicep/ast/Variables.qll index 476a030..10cc798 100644 --- a/ql/lib/codeql/bicep/ast/Variables.qll +++ b/ql/lib/codeql/bicep/ast/Variables.qll @@ -7,3 +7,20 @@ private import Idents private import Stmts private import codeql.bicep.controlflow.BasicBlocks as BasicBlocks private import codeql.bicep.controlflow.ControlFlowGraph +// Internal +private import internal.VariableDeclaration + +/** + * A VariableDeclaration unknown AST node. + */ +class VariableDeclaration extends AstNode instanceof VariableDeclarationImpl { + /** + * Gets the identifier of the variable declaration. + */ + Idents getIdentifier() { result = VariableDeclarationImpl.super.getIdentifier() } + + /** + * Gets the initializer expression of the variable declaration. + */ + Expr getInitializer() { result = VariableDeclarationImpl.super.getInitializer() } +} diff --git a/ql/lib/codeql/bicep/ast/internal/AssignmentExpression.qll b/ql/lib/codeql/bicep/ast/internal/AssignmentExpression.qll index c9c285e..2fc9cbc 100644 --- a/ql/lib/codeql/bicep/ast/internal/AssignmentExpression.qll +++ b/ql/lib/codeql/bicep/ast/internal/AssignmentExpression.qll @@ -3,12 +3,12 @@ * * WARNING: this file is generated, do not edit manually */ + private import AstNodes private import TreeSitter private import codeql.bicep.ast.AstNodes private import Expr - /** * A AssignmentExpression AST Node. */ @@ -21,6 +21,7 @@ class AssignmentExpressionImpl extends TAssignmentExpression, ExprImpl { override string toString() { result = ast.toString() } + ExprImpl getLeft() { toTreeSitter(result) = ast.getLeft() } - -} \ No newline at end of file + ExprImpl getRight() { toTreeSitter(result) = ast.getRight() } +} diff --git a/ql/lib/codeql/bicep/ast/internal/AstNodes.qll b/ql/lib/codeql/bicep/ast/internal/AstNodes.qll index 464d2c3..6f6b6cc 100644 --- a/ql/lib/codeql/bicep/ast/internal/AstNodes.qll +++ b/ql/lib/codeql/bicep/ast/internal/AstNodes.qll @@ -88,7 +88,7 @@ class TIdents = TIdentifier or TPropertyIdentifier; */ class TStmts = TInfrastructure or TAssertStatement or TForStatement or TIfStatement or TImportStatement or - TImportWithStatement or TStatement or TUsingStatement; + TImportWithStatement or TStatement or TUsingStatement or TVariableDeclaration; /** * A expersion value in a Bicep program diff --git a/ql/lib/codeql/bicep/ast/internal/BinaryExpression.qll b/ql/lib/codeql/bicep/ast/internal/BinaryExpression.qll index ee938a2..328a3af 100644 --- a/ql/lib/codeql/bicep/ast/internal/BinaryExpression.qll +++ b/ql/lib/codeql/bicep/ast/internal/BinaryExpression.qll @@ -21,6 +21,12 @@ class BinaryExpressionImpl extends TBinaryExpression, ExprImpl { override string toString() { result = ast.toString() } + ExprImpl getLeft() { toTreeSitter(result) = ast.getLeft() } + ExprImpl getRight() { toTreeSitter(result) = ast.getRight() } + + string getOperator() { + result = ast.getOperator() + } } \ No newline at end of file diff --git a/ql/lib/codeql/bicep/ast/internal/IfStatement.qll b/ql/lib/codeql/bicep/ast/internal/IfStatement.qll index ff91130..9ac4054 100644 --- a/ql/lib/codeql/bicep/ast/internal/IfStatement.qll +++ b/ql/lib/codeql/bicep/ast/internal/IfStatement.qll @@ -3,11 +3,13 @@ * * WARNING: this file is generated, do not edit manually */ + private import AstNodes private import TreeSitter private import codeql.bicep.ast.AstNodes private import Stmts - +private import ParenthesizedExpression +private import Object /** * A IfStatement AST Node. @@ -21,6 +23,7 @@ class IfStatementImpl extends TIfStatement, StmtsImpl { override string toString() { result = ast.toString() } + ParenthesizedExpressionImpl getCondition() { toTreeSitter(result) = ast.getChild(0) } - -} \ No newline at end of file + ObjectImpl getBody() { toTreeSitter(result) = ast.getChild(1) } +} diff --git a/ql/lib/codeql/bicep/ast/internal/Interpolation.qll b/ql/lib/codeql/bicep/ast/internal/Interpolation.qll index 00d7ff0..761920d 100644 --- a/ql/lib/codeql/bicep/ast/internal/Interpolation.qll +++ b/ql/lib/codeql/bicep/ast/internal/Interpolation.qll @@ -21,4 +21,7 @@ class InterpolationImpl extends TInterpolation, ExprImpl { override string toString() { result = ast.toString() } + ExprImpl getExpression() { + toTreeSitter(result) = ast.getChild() + } } \ No newline at end of file diff --git a/ql/lib/codeql/bicep/ast/internal/ParenthesizedExpression.qll b/ql/lib/codeql/bicep/ast/internal/ParenthesizedExpression.qll index 8264194..bbe0241 100644 --- a/ql/lib/codeql/bicep/ast/internal/ParenthesizedExpression.qll +++ b/ql/lib/codeql/bicep/ast/internal/ParenthesizedExpression.qll @@ -3,12 +3,12 @@ * * WARNING: this file is generated, do not edit manually */ + private import AstNodes private import TreeSitter private import codeql.bicep.ast.AstNodes private import Expr - /** * A ParenthesizedExpression AST Node. */ @@ -21,6 +21,7 @@ class ParenthesizedExpressionImpl extends TParenthesizedExpression, ExprImpl { override string toString() { result = ast.toString() } + ExprImpl getExpression(int index) { toTreeSitter(result) = ast.getChild(index) } - -} \ No newline at end of file + ExprImpl getExpressions() { result = this.getExpression(_) } +} diff --git a/ql/lib/codeql/bicep/ast/internal/String.qll b/ql/lib/codeql/bicep/ast/internal/String.qll index d0c05a4..c553eb2 100644 --- a/ql/lib/codeql/bicep/ast/internal/String.qll +++ b/ql/lib/codeql/bicep/ast/internal/String.qll @@ -3,12 +3,12 @@ * * WARNING: this file is generated, do not edit manually */ + private import AstNodes private import TreeSitter private import codeql.bicep.ast.AstNodes private import Literals - /** * A String AST Node. */ @@ -20,13 +20,15 @@ class StringImpl extends TString, LiteralsImpl { StringImpl() { this = TString(ast) } override string toString() { result = ast.toString() } + /** * Get the literal value - * + * * TODO: This is broken. */ override string getValue() { result = ast.getChild(_).toString() } - - -} \ No newline at end of file + AstNode getChild(int index) { + toTreeSitter(result) = ast.getChild(index) + } +} diff --git a/ql/lib/codeql/bicep/ast/internal/SubscriptExpression.qll b/ql/lib/codeql/bicep/ast/internal/SubscriptExpression.qll index aa5bbaf..2be82c8 100644 --- a/ql/lib/codeql/bicep/ast/internal/SubscriptExpression.qll +++ b/ql/lib/codeql/bicep/ast/internal/SubscriptExpression.qll @@ -3,12 +3,12 @@ * * WARNING: this file is generated, do not edit manually */ + private import AstNodes private import TreeSitter private import codeql.bicep.ast.AstNodes private import Expr - /** * A SubscriptExpression AST Node. */ @@ -21,6 +21,7 @@ class SubscriptExpressionImpl extends TSubscriptExpression, ExprImpl { override string toString() { result = ast.toString() } + ExprImpl getIndex() { toTreeSitter(result) = ast.getIndex() } - -} \ No newline at end of file + ExprImpl getObject() { toTreeSitter(result) = ast.getObject() } +} diff --git a/ql/lib/codeql/bicep/ast/internal/VariableDeclaration.qll b/ql/lib/codeql/bicep/ast/internal/VariableDeclaration.qll index dbea854..37100b7 100644 --- a/ql/lib/codeql/bicep/ast/internal/VariableDeclaration.qll +++ b/ql/lib/codeql/bicep/ast/internal/VariableDeclaration.qll @@ -3,14 +3,18 @@ * * WARNING: this file is generated, do not edit manually */ + private import AstNodes private import TreeSitter private import codeql.bicep.ast.AstNodes +private import Stmts +private import Idents +private import Expr /** * A VariableDeclaration AST Node. */ -class VariableDeclarationImpl extends TVariableDeclaration, AstNode { +class VariableDeclarationImpl extends TVariableDeclaration, StmtsImpl { private BICEP::VariableDeclaration ast; override string getAPrimaryQlClass() { result = "VariableDeclaration" } @@ -19,6 +23,7 @@ class VariableDeclarationImpl extends TVariableDeclaration, AstNode { override string toString() { result = ast.toString() } + IdentsImpl getIdentifier() { toTreeSitter(result) = ast.getChild(0) } - -} \ No newline at end of file + ExprImpl getInitializer() { toTreeSitter(result) = ast.getChild(1) } +} diff --git a/ql/test/library-tests/ast/AST.expected b/ql/test/library-tests/ast/AST.expected index 775a7d7..5b111ed 100644 --- a/ql/test/library-tests/ast/AST.expected +++ b/ql/test/library-tests/ast/AST.expected @@ -1,3 +1,100 @@ +ast +| conditions.bicep:1:1:1:39 | ParameterDeclaration | +| conditions.bicep:1:1:1:39 | ParameterDeclaration | +| conditions.bicep:1:1:1:39 | ParameterDeclaration | +| conditions.bicep:1:1:12:2 | Infrastructure | +| conditions.bicep:1:7:1:26 | enableStorageAccount | +| conditions.bicep:1:7:1:26 | enableStorageAccount | +| conditions.bicep:1:7:1:26 | enableStorageAccount | +| conditions.bicep:1:28:1:31 | Type | +| conditions.bicep:1:28:1:31 | bool | +| conditions.bicep:1:35:1:39 | false | +| conditions.bicep:1:35:1:39 | false | +| conditions.bicep:1:35:1:39 | false | +| conditions.bicep:2:1:2:54 | ParameterDeclaration | +| conditions.bicep:2:1:2:54 | ParameterDeclaration | +| conditions.bicep:2:1:2:54 | ParameterDeclaration | +| conditions.bicep:2:7:2:24 | storageAccountName | +| conditions.bicep:2:7:2:24 | storageAccountName | +| conditions.bicep:2:7:2:24 | storageAccountName | +| conditions.bicep:2:26:2:31 | Type | +| conditions.bicep:2:26:2:31 | string | +| conditions.bicep:2:35:2:54 | String | +| conditions.bicep:2:35:2:54 | String | +| conditions.bicep:2:35:2:54 | String | +| conditions.bicep:2:36:2:53 | examplestorageacct | +| conditions.bicep:4:1:12:1 | ResourceDeclaration | +| conditions.bicep:4:1:12:1 | ResourceDeclaration | +| conditions.bicep:4:1:12:1 | ResourceDeclaration | +| conditions.bicep:4:10:4:23 | storageAccount | +| conditions.bicep:4:10:4:23 | storageAccount | +| conditions.bicep:4:10:4:23 | storageAccount | +| conditions.bicep:4:25:4:70 | String | +| conditions.bicep:4:25:4:70 | String | +| conditions.bicep:4:25:4:70 | String | +| conditions.bicep:4:26:4:69 | Microsoft.Storage/storageAccounts@2022-09-01 | +| conditions.bicep:4:74:12:1 | IfStatement | +| conditions.bicep:4:77:4:98 | ParenthesizedExpression | +| conditions.bicep:4:77:4:98 | ParenthesizedExpression | +| conditions.bicep:4:77:4:98 | ParenthesizedExpression | +| conditions.bicep:4:78:4:97 | enableStorageAccount | +| conditions.bicep:4:78:4:97 | enableStorageAccount | +| conditions.bicep:4:78:4:97 | enableStorageAccount | +| conditions.bicep:4:100:12:1 | Object | +| conditions.bicep:4:100:12:1 | Object | +| conditions.bicep:4:100:12:1 | Object | +| conditions.bicep:5:3:5:6 | name | +| conditions.bicep:5:3:5:6 | name | +| conditions.bicep:5:3:5:6 | name | +| conditions.bicep:5:3:5:26 | ObjectProperty | +| conditions.bicep:5:9:5:26 | storageAccountName | +| conditions.bicep:5:9:5:26 | storageAccountName | +| conditions.bicep:5:9:5:26 | storageAccountName | +| conditions.bicep:6:3:6:10 | location | +| conditions.bicep:6:3:6:10 | location | +| conditions.bicep:6:3:6:10 | location | +| conditions.bicep:6:3:6:36 | ObjectProperty | +| conditions.bicep:6:13:6:25 | resourceGroup | +| conditions.bicep:6:13:6:25 | resourceGroup | +| conditions.bicep:6:13:6:25 | resourceGroup | +| conditions.bicep:6:13:6:27 | CallExpression | +| conditions.bicep:6:13:6:27 | CallExpression | +| conditions.bicep:6:13:6:27 | CallExpression | +| conditions.bicep:6:13:6:36 | MemberExpression | +| conditions.bicep:6:13:6:36 | MemberExpression | +| conditions.bicep:6:13:6:36 | MemberExpression | +| conditions.bicep:6:26:6:27 | Arguments | +| conditions.bicep:6:29:6:36 | location | +| conditions.bicep:7:3:7:5 | sku | +| conditions.bicep:7:3:7:5 | sku | +| conditions.bicep:7:3:7:5 | sku | +| conditions.bicep:7:3:9:3 | ObjectProperty | +| conditions.bicep:7:8:9:3 | Object | +| conditions.bicep:7:8:9:3 | Object | +| conditions.bicep:7:8:9:3 | Object | +| conditions.bicep:8:5:8:8 | name | +| conditions.bicep:8:5:8:8 | name | +| conditions.bicep:8:5:8:8 | name | +| conditions.bicep:8:5:8:24 | ObjectProperty | +| conditions.bicep:8:11:8:24 | String | +| conditions.bicep:8:11:8:24 | String | +| conditions.bicep:8:11:8:24 | String | +| conditions.bicep:8:12:8:23 | Standard_LRS | +| conditions.bicep:10:3:10:6 | kind | +| conditions.bicep:10:3:10:6 | kind | +| conditions.bicep:10:3:10:6 | kind | +| conditions.bicep:10:3:10:19 | ObjectProperty | +| conditions.bicep:10:9:10:19 | String | +| conditions.bicep:10:9:10:19 | String | +| conditions.bicep:10:9:10:19 | String | +| conditions.bicep:10:10:10:18 | StorageV2 | +| conditions.bicep:11:3:11:12 | properties | +| conditions.bicep:11:3:11:12 | properties | +| conditions.bicep:11:3:11:12 | properties | +| conditions.bicep:11:3:11:16 | ObjectProperty | +| conditions.bicep:11:15:11:16 | Object | +| conditions.bicep:11:15:11:16 | Object | +| conditions.bicep:11:15:11:16 | Object | | data.bicep:1:1:1:10 | Comment | | data.bicep:1:1:62:4 | Infrastructure | | data.bicep:2:1:6:1 | VariableDeclaration | @@ -1013,3 +1110,62 @@ | sample.bicep:98:15:98:20 | MemberExpression | | sample.bicep:98:15:98:20 | MemberExpression | | sample.bicep:98:19:98:20 | id | +strings +| conditions.bicep:2:35:2:54 | String | examplestorageacct | +| conditions.bicep:4:25:4:70 | String | Microsoft.Storage/storageAccounts@2022-09-01 | +| conditions.bicep:8:11:8:24 | String | Standard_LRS | +| conditions.bicep:10:9:10:19 | String | StorageV2 | +| data.bicep:3:3:3:7 | String | abc | +| data.bicep:4:3:4:7 | String | def | +| data.bicep:5:3:5:7 | String | ghi | +| data.bicep:8:24:8:28 | String | abc | +| data.bicep:8:31:8:35 | String | def | +| data.bicep:8:38:8:42 | String | ghi | +| data.bicep:10:19:10:23 | String | abc | +| data.bicep:10:26:10:30 | String | def | +| data.bicep:11:5:11:9 | String | ghi | +| data.bicep:27:40:27:50 | String | test name | +| data.bicep:27:57:27:65 | String | 123-abc | +| data.bicep:30:9:30:19 | String | test name | +| data.bicep:31:7:31:15 | String | 123-abc | +| data.bicep:36:35:36:45 | String | test name | +| data.bicep:36:52:36:60 | String | 123-abc | +| data.bicep:41:13:41:25 | String | whats up? | +| data.bicep:42:18:42:24 | String | north | +| data.bicep:42:28:42:34 | String | south | +| data.bicep:42:38:42:43 | String | east | +| data.bicep:42:47:42:52 | String | west | +| data.bicep:43:19:43:62 | String | storage${CallExpression} | +| data.bicep:46:13:46:24 | String | hello! | +| data.bicep:49:14:50:9 | String | \nhello! | +| data.bicep:53:14:55:3 | String | \nhello!\n | +| data.bicep:58:14:62:3 | String | \n this\n is\n indented\n | +| sample.bicep:2:35:2:80 | String | toylaunch${CallExpression} | +| sample.bicep:3:23:3:28 | String | myVM | +| sample.bicep:4:30:4:40 | String | azureuser | +| sample.bicep:5:30:5:43 | String | P@ssw0rd123! | +| sample.bicep:6:25:6:32 | String | myVnet | +| sample.bicep:7:27:7:36 | String | mySubnet | +| sample.bicep:8:29:8:40 | String | myPublicIP | +| sample.bicep:9:24:9:30 | String | myNIC | +| sample.bicep:11:25:11:70 | String | Microsoft.Storage/storageAccounts@2021-06-01 | +| sample.bicep:15:11:15:24 | String | Standard_LRS | +| sample.bicep:17:9:17:19 | String | StorageV2 | +| sample.bicep:19:17:19:21 | String | Hot | +| sample.bicep:23:15:23:60 | String | Microsoft.Network/virtualNetworks@2021-05-01 | +| sample.bicep:29:9:29:21 | String | 10.0.0.0/16 | +| sample.bicep:36:26:36:38 | String | 10.0.0.0/24 | +| sample.bicep:43:19:43:66 | String | Microsoft.Network/publicIPAddresses@2021-05-01 | +| sample.bicep:47:31:47:39 | String | Dynamic | +| sample.bicep:51:14:51:61 | String | Microsoft.Network/networkInterfaces@2021-05-01 | +| sample.bicep:57:15:57:25 | String | ipconfig1 | +| sample.bicep:62:38:62:46 | String | Dynamic | +| sample.bicep:72:13:72:58 | String | Microsoft.Compute/virtualMachines@2021-07-01 | +| sample.bicep:77:15:77:31 | String | Standard_DS1_v2 | +| sample.bicep:86:20:86:30 | String | Canonical | +| sample.bicep:87:16:87:29 | String | UbuntuServer | +| sample.bicep:88:14:88:24 | String | 18.04-LTS | +| sample.bicep:89:18:89:25 | String | latest | +| sample.bicep:92:23:92:33 | String | FromImage | +ifCondition +| conditions.bicep:4:74:12:1 | IfStatement | conditions.bicep:4:77:4:98 | ParenthesizedExpression | conditions.bicep:4:100:12:1 | Object | diff --git a/ql/test/library-tests/ast/AST.ql b/ql/test/library-tests/ast/AST.ql index 1c30357..63e19a1 100644 --- a/ql/test/library-tests/ast/AST.ql +++ b/ql/test/library-tests/ast/AST.ql @@ -1,3 +1,10 @@ private import bicep query predicate ast(AstNode ast) { any() } + +query predicate strings(String str, string output) { output = str.getValue() } + +query predicate ifCondition(IfStatement ifStmt, Expr condition, Expr body) { + ifStmt.getCondition() = condition and + ifStmt.getBody() = body +} diff --git a/ql/test/library-tests/ast/conditions.bicep b/ql/test/library-tests/ast/conditions.bicep new file mode 100644 index 0000000..e2bd6a3 --- /dev/null +++ b/ql/test/library-tests/ast/conditions.bicep @@ -0,0 +1,12 @@ +param enableStorageAccount bool = false +param storageAccountName string = 'examplestorageacct' + +resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = if (enableStorageAccount) { + name: storageAccountName + location: resourceGroup().location + sku: { + name: 'Standard_LRS' + } + kind: 'StorageV2' + properties: {} +}