Skip to content

Commit

Permalink
Unit test for flows from global variable (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
pandurangpatil authored Feb 28, 2023
1 parent de24046 commit 5497c22
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,36 @@ class DataFlowTests extends PySrc2CpgFixture(withOssDataflow = true) {
}
}

"flow from global variable to sink" in {
val cpg: Cpg = code("""
|import requests
|url = "https://app.commissionly.io/api/public/opportunity"
|
|class CommissionlyClient:
| def post_data(self, data, accountId):
| r = requests.post(
| url,
| json={"isloop": True, "data": accountId},
| auth=data.password,
| )
|
|client = CommissionlyClient()
|data = {"key1": "value1"}
|accountId="sometext"
|response = client.post_data(data, accountId)
|""".stripMargin)
val source = cpg.identifier(".*url.*").l
val sink = cpg.call("post").l
source.size shouldBe 2
sink.size shouldBe 1
val flows = sink.reachableByFlows(source).l
flows.size shouldBe 1

val sourcel = cpg.literal(".*app.commissionly.io.*").l
sourcel.size shouldBe 1

val flowsl = sink.reachableByFlows(source).l
flowsl.size shouldBe 1
}

}

0 comments on commit 5497c22

Please sign in to comment.