Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.

Commit 833d5b8

Browse files
stishkinstas
andauthored
Yaml support - Add job definition yaml support - Explicitly expose yaml swagger Rest Api Fuzz Testing service definition (#51)
Co-authored-by: stas <[email protected]>
1 parent 40c1c97 commit 833d5b8

File tree

11 files changed

+219
-5
lines changed

11 files changed

+219
-5
lines changed

cli/raft_sdk/raft_service.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
# Licensed under the MIT License.
33

44
import json
5+
import yaml
56
import os
67
import sys
78
import time
9+
from pathlib import Path
810

911
import tabulate
1012
from .raft_common import RaftApiException, RestApiClient, RaftDefinitions
1113

1214
script_dir = os.path.dirname(os.path.abspath(__file__))
1315
dos2unix_file_types = [".sh", ".bash"]
1416

15-
1617
class RaftJobConfig():
1718
def __init__(self,
1819
*,
@@ -24,7 +25,15 @@ def __init__(self,
2425
c = config_file.read()
2526
for src in substitutions:
2627
c = c.replace(src, substitutions[src])
27-
config = json.loads(c)
28+
29+
ext = Path(file_path).suffix
30+
if ext == '.json':
31+
config = json.loads(c)
32+
elif ext == '.yml' or ext == '.yaml':
33+
config= yaml.load(c, Loader= yaml.FullLoader)
34+
else:
35+
raise Exception('Unsupported config file type')
36+
2837
self.config = config
2938
elif json:
3039
self.config = json_config

cli/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
msal~=1.4.3
22
requests~=2.24.0
33
tabulate~=0.8.7
4+
pyyaml~=5.3.1

cli/samples/multiple-tools/running-against-raft-using-restler-and-zap/combined.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def run(compile, fuzz, sample_host):
1616
subs = {
1717
'{sample.host}' : sample_host,
1818
'{defaults.deploymentName}' : cli.definitions.deployment
19-
2019
}
2120
compile_job_config = raft.RaftJobConfig(file_path=compile, substitutions=subs)
2221
print('Compile')
@@ -35,6 +34,6 @@ def run(compile, fuzz, sample_host):
3534
substitute {sample.host} in compile.json and fuzz.json config files')
3635
else:
3736
host = sys.argv[1]
38-
run(os.path.join(cur_dir, "compile.json"),
37+
run(os.path.join(cur_dir, "compile.yaml"),
3938
os.path.join(cur_dir, "fuzz.json"),
4039
host)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
swaggerLocation:
2+
URL: "https://{defaults.deploymentName}-raft-apiservice.azurewebsites.net/swagger/v1/swagger.json"
3+
4+
tasks:
5+
- toolName: "RESTler"
6+
outputFolder: "{defaults.deploymentName}-compile"
7+
toolConfiguration:
8+
task : Compile
9+
compileConfiguration:
10+
useRefreshableToken: true
11+
12+
- toolName: "RESTler"
13+
outputFolder: "sample-compile"
14+
swaggerLocation:
15+
URL: "https://{sample.host}/swagger/v1/swagger.json"
16+
toolConfiguration:
17+
task : Compile
18+
compileConfiguration:
19+
useRefreshableToken: true
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
import pathlib
5+
import sys
6+
import os
7+
import json
8+
import urllib.parse
9+
10+
cur_dir = os.path.dirname(os.path.abspath(__file__))
11+
sys.path.append(os.path.join(cur_dir, '..', '..', '..'))
12+
from raft_sdk.raft_service import RaftCLI, RaftJobConfig
13+
14+
def run(replay, fuzz_job_id, replay_job_id=None):
15+
cli = RaftCLI()
16+
substitutions = {
17+
'{defaults.deploymentName}': cli.definitions.deployment,
18+
'{jobRunId}' : fuzz_job_id
19+
}
20+
replay_job_config = RaftJobConfig(file_path=replay, substitutions=substitutions)
21+
22+
print('Replay')
23+
isIdle = False
24+
for task in replay_job_config.config['tasks']:
25+
isIdle = isIdle or task['isIdling']
26+
27+
if isIdle and replay_job_id:
28+
cli.update_job(replay_job_id, replay_job_config)
29+
print(f'Idle Job: {replay_job_id}')
30+
else:
31+
# create new fuzz job configuration
32+
replay_job_id = cli.new_job(replay_job_config)
33+
if isIdle:
34+
print(f'New Idle Job: {replay_job_id}')
35+
else:
36+
print(f'New Job: {replay_job_id}')
37+
38+
if not isIdle:
39+
# wait for job ID from fuzz_job to finish the run
40+
cli.poll(replay_job_id['jobId'])
41+
42+
43+
if __name__ == "__main__":
44+
run(replay = "raft.restler.replay.json",
45+
#job ID that produced bugs and those bugs going to be replayed
46+
fuzz_job_id = "d29c7a2a-1815-4edb-91c1-56dd4faea0ce",
47+
replay_job_id=None)
48+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
import pathlib
5+
import sys
6+
import os
7+
import json
8+
import urllib.parse
9+
10+
cur_dir = os.path.dirname(os.path.abspath(__file__))
11+
sys.path.append(os.path.join(cur_dir, '..', '..', '..'))
12+
from raft_sdk.raft_service import RaftCLI, RaftJobConfig
13+
14+
def run(compile, test, fuzz):
15+
# instantiate RAFT CLI
16+
cli = RaftCLI()
17+
substitutions = {
18+
'{defaults.deploymentName}': cli.definitions.deployment
19+
}
20+
compile_job_config = RaftJobConfig(file_path=compile, substitutions=substitutions)
21+
print('Compile')
22+
# create a new job with the Compile config and get new job ID
23+
# in compile_job
24+
compile_job = cli.new_job(compile_job_config)
25+
# wait for a job with ID from compile_job to finish the run
26+
cli.poll(compile_job['jobId'])
27+
substitutions['{compile.jobId}'] = compile_job['jobId']
28+
29+
print('Test')
30+
test_job_config = RaftJobConfig(file_path=test, substitutions=substitutions)
31+
test_job = cli.new_job(test_job_config)
32+
cli.poll(test_job['jobId'])
33+
34+
print('Fuzz')
35+
fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=substitutions)
36+
fuzz_job = cli.new_job(fuzz_job_config)
37+
cli.poll(fuzz_job['jobId'])
38+
39+
if __name__ == "__main__":
40+
run(os.path.join(cur_dir, "raft.restler.compile.yaml"),
41+
os.path.join(cur_dir, "raft.restler.test.yaml"),
42+
os.path.join(cur_dir, "raft.restler.fuzz.yaml"))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
swaggerLocation:
2+
Url: https://{defaults.deploymentName}-raft-apiservice.azurewebsites.net/swagger/v1/swagger.json
3+
rootFileShare: raft
4+
tasks:
5+
- toolName: RESTler
6+
outputFolder: compile
7+
toolConfiguration:
8+
task: compile
9+
compileConfiguration:
10+
useRefreshableToken: true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
duration: 00:10:00
2+
host: {defaults.deploymentName}-raft-apiservice.azurewebsites.net
3+
rootFileShare: raft
4+
readOnlyFileShareMounts:
5+
- FileShareName: raft
6+
MountPath: /job-compile
7+
tasks:
8+
- toolName: RESTler
9+
outputFolder: fuzz-1
10+
keyVaultSecrets:
11+
- RaftServicePrincipal
12+
authenticationMethod:
13+
MSAL: RaftServicePrincipal
14+
toolConfiguration:
15+
task: Fuzz
16+
runConfiguration:
17+
inputFolderPath: /job-compile/{compile.jobId}/compile
18+
19+
- toolName: RESTler
20+
outputFolder: RESTler-fuzz-random-walk-2
21+
keyVaultSecrets:
22+
- RaftServicePrincipal
23+
authenticationMethod:
24+
MSAL: RaftServicePrincipal
25+
toolConfiguration:
26+
task: FuzzRandomWalk
27+
runConfiguration:
28+
inputFolderPath: /job-compile/{compile.jobId}/compile
29+
- toolName: RESTler
30+
outputFolder: RESTler-fuzz-bfscheap-3
31+
keyVaultSecrets:
32+
- RaftServicePrincipal
33+
authenticationMethod:
34+
MSAL: RaftServicePrincipal
35+
toolConfiguration:
36+
task: FuzzBfsCheap
37+
runConfiguration:
38+
inputFolderPath: /job-compile/{compile.jobId}/compile
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
host: {defaults.deploymentName}-raft-apiservice.azurewebsites.net
2+
rootFileShare: raft
3+
readOnlyFileShareMounts:
4+
- FileShareName: raft
5+
MountPath: /job-run
6+
tasks:
7+
- toolName: RESTler
8+
outputFolder: RESTLer-replay
9+
keyVaultSecrets:
10+
- RaftServicePrincipal
11+
authenticationMethod:
12+
MSAL: RaftServicePrincipal
13+
toolConfiguration:
14+
task: Replay
15+
runConfiguration:
16+
inputFolderPath: /job-run/{jobRunId}/fuzz-1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
host: {defaults.deploymentName}-raft-apiservice.azurewebsites.net
2+
rootFileShare: raft
3+
readOnlyFileShareMounts:
4+
- FileShareName: raft
5+
MountPath: "/job-compile"
6+
tasks:
7+
- toolName: RESTler
8+
outputFolder: RESTler-test
9+
keyVaultSecrets:
10+
- RaftServicePrincipal
11+
authenticationMethod:
12+
MSAL: RaftServicePrincipal
13+
toolConfiguration:
14+
task: Test
15+
runConfiguration:
16+
inputFolderPath: /job-compile/{compile.jobId}/compile
17+
- toolName: RESTler
18+
outputFolder: RESTler-test-fuzz-lean
19+
keyVaultSecrets:
20+
- RaftServicePrincipal
21+
authenticationMethod:
22+
MSAL: RaftServicePrincipal
23+
toolConfiguration:
24+
task: TestFuzzLean
25+
runConfiguration:
26+
inputFolderPath: /job-compile/{compile.jobId}/compile
27+
authenticationTokenRefreshIntervalSeconds: 300

0 commit comments

Comments
 (0)