Skip to content

Commit 825a795

Browse files
committed
finalize split-up between wep-api-testing adn web-api-documentation
1 parent c7befb7 commit 825a795

File tree

12 files changed

+66
-77
lines changed

12 files changed

+66
-77
lines changed

‎src/hackingBuddyGPT/usecases/web_api_documentation/openapi_specification_handler.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from hackingBuddyGPT.capabilities.yamlFile import YAMLFile
1010
from hackingBuddyGPT.utils.web_api.pattern_matcher import PatternMatcher
1111
from hackingBuddyGPT.utils.prompt_generation.information import PromptStrategy
12-
from hackingBuddyGPT.usecases.web_api_testing.utils import LLMHandler
12+
from hackingBuddyGPT.utils.web_api.llm_handler import LLMHandler
1313

1414

1515
class OpenAPISpecificationHandler(object):

‎src/hackingBuddyGPT/usecases/web_api_documentation/simple_openapi_documentation.py‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
from logging import config
13
import os
24
from dataclasses import field
35

@@ -10,13 +12,13 @@
1012
OpenAPISpecificationHandler
1113
from hackingBuddyGPT.utils.capability_manager import CapabilityManager
1214
from hackingBuddyGPT.utils.logging import Logger, log_param
15+
from hackingBuddyGPT.utils.prompt_generation.information.prompt_information import PromptStrategy
1316
from hackingBuddyGPT.utils.prompt_generation.prompt_generation_helper import PromptGenerationHelper
1417
from hackingBuddyGPT.utils.prompt_generation.information import PromptContext
1518
from hackingBuddyGPT.utils.prompt_generation.prompt_engineer import PromptEngineer
16-
from hackingBuddyGPT.usecases.web_api_testing.utils.response_handler import ResponseHandler
17-
from hackingBuddyGPT.usecases.web_api_testing.utils import LLMHandler
18-
from hackingBuddyGPT.usecases.web_api_testing.utils.configuration_handler import ConfigurationHandler
19-
from hackingBuddyGPT.usecases.web_api_testing.utils.custom_datatypes import Context, Prompt
19+
from hackingBuddyGPT.utils.web_api.response_handler import ResponseHandler
20+
from hackingBuddyGPT.utils.web_api.llm_handler import LLMHandler
21+
from hackingBuddyGPT.utils.web_api.custom_datatypes import Context, Prompt
2022
from hackingBuddyGPT.usecases.web_api_documentation.evaluator import Evaluator
2123
from hackingBuddyGPT.utils.configurable import parameter
2224
from hackingBuddyGPT.utils.openai.openai_lib import OpenAILib
@@ -77,6 +79,15 @@ class SimpleWebAPIDocumentation(AutonomousUseCase):
7779

7880
def get_name(self) -> str:
7981
return self.__class__.__name__
82+
83+
def get_strategy(self, strategy_string):
84+
85+
strategies = {
86+
"cot": PromptStrategy.CHAIN_OF_THOUGHT,
87+
"tot": PromptStrategy.TREE_OF_THOUGHT,
88+
"icl": PromptStrategy.IN_CONTEXT
89+
}
90+
return strategies.get(strategy_string, PromptStrategy.IN_CONTEXT)
8091

8192
def init(self):
8293
"""Initialize the agent with configurations, capabilities, and handlers."""
@@ -85,10 +96,19 @@ def init(self):
8596
self.found_all_http_methods = False
8697
self.all_steps_done = False
8798

88-
89-
config_handler = ConfigurationHandler(self.config_path, self.strategy_string)
90-
config, self.strategy = config_handler.load()
91-
token, self.host, description, self._correct_endpoints, query_params = config_handler._extract_config_values(config)
99+
# load config file
100+
self.strategy = self.get_strategy(self.strategy_string)
101+
102+
"""Loads JSON configuration from the specified path."""
103+
if not os.path.exists(self.config_path):
104+
raise FileNotFoundError(f"Configuration file not found at {self.config_path}")
105+
with open(self.config_path, 'r') as file:
106+
config = json.load(file)
107+
token = config.get("token")
108+
self.host = config.get("host")
109+
description = config.get("description")
110+
self._correct_endpoints = config.get("correct_endpoints", {})
111+
query_params = config.get("query_params", {})
92112

93113
self.categorized_endpoints = self.categorize_endpoints(self._correct_endpoints, query_params)
94114

‎src/hackingBuddyGPT/usecases/web_api_testing/simple_web_api_testing.py‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
from hackingBuddyGPT.capabilities.record_note import RecordNote
1515
from hackingBuddyGPT.usecases.base import AutonomousUseCase, use_case
1616
from hackingBuddyGPT.utils.capability_manager import CapabilityManager
17+
from hackingBuddyGPT.utils.prompt_generation.information.prompt_information import PromptStrategy
1718
from hackingBuddyGPT.utils.prompt_generation.prompt_generation_helper import PromptGenerationHelper
1819
from hackingBuddyGPT.utils.prompt_generation.information import PenTestingInformation
1920
from hackingBuddyGPT.utils.prompt_generation.information import PromptPurpose
2021
from hackingBuddyGPT.utils.openapi.openapi_parser import OpenAPISpecificationParser
2122
from hackingBuddyGPT.usecases.web_api_testing.report_handler import ReportHandler
2223
from hackingBuddyGPT.utils.prompt_generation.information import PromptContext
2324
from hackingBuddyGPT.utils.prompt_generation.prompt_engineer import PromptEngineer
24-
from hackingBuddyGPT.usecases.web_api_testing.utils.response_analyzer_with_llm import \
25+
from hackingBuddyGPT.utils.web_api.response_analyzer_with_llm import \
2526
ResponseAnalyzerWithLLM
26-
from hackingBuddyGPT.usecases.web_api_testing.utils.response_handler import ResponseHandler
27+
from hackingBuddyGPT.utils.web_api.response_handler import ResponseHandler
2728
from hackingBuddyGPT.usecases.web_api_testing.test_handler import GenerationTestHandler
28-
from hackingBuddyGPT.usecases.web_api_testing.utils.configuration_handler import ConfigurationHandler
29-
from hackingBuddyGPT.usecases.web_api_testing.utils.custom_datatypes import Context, Prompt
30-
from hackingBuddyGPT.usecases.web_api_testing.utils.llm_handler import LLMHandler
29+
from hackingBuddyGPT.utils.web_api.custom_datatypes import Context, Prompt
30+
from hackingBuddyGPT.utils.web_api.llm_handler import LLMHandler
3131
from hackingBuddyGPT.utils import tool_message
3232
from hackingBuddyGPT.utils.configurable import parameter
3333
from hackingBuddyGPT.utils.openai.openai_lib import OpenAILib
@@ -73,12 +73,32 @@ class SimpleWebAPITesting(AutonomousUseCase):
7373
_capabilities: CapabilityManager = None
7474
_all_test_cases_run: bool = False
7575

76+
def get_strategy(self, strategy_string):
77+
78+
strategies = {
79+
"cot": PromptStrategy.CHAIN_OF_THOUGHT,
80+
"tot": PromptStrategy.TREE_OF_THOUGHT,
81+
"icl": PromptStrategy.IN_CONTEXT
82+
}
83+
return strategies.get(strategy_string, PromptStrategy.IN_CONTEXT)
84+
7685
def init(self):
7786
super().init()
78-
configuration_handler = ConfigurationHandler(self.config_path, self.strategy_string)
79-
self.config, self.strategy = configuration_handler.load()
80-
self.token, self.host, self.description, self.correct_endpoints, self.query_params = configuration_handler._extract_config_values(
81-
self.config)
87+
88+
# load config file
89+
self.strategy = self.get_strategy(self.strategy_string)
90+
91+
"""Loads JSON configuration from the specified path."""
92+
if not os.path.exists(self.config_path):
93+
raise FileNotFoundError(f"Configuration file not found at {self.config_path}")
94+
with open(self.config_path, 'r') as file:
95+
self.config = json.load(file)
96+
self.token = self.config.get("token")
97+
self.host = self.config.get("host")
98+
self.description = self.config.get("description")
99+
self.correct_endpoints = self.config.get("correct_endpoints", {})
100+
self.query_params = self.config.get("query_params", {})
101+
82102
self._load_openapi_specification()
83103
self._setup_environment()
84104
self._setup_handlers()

‎src/hackingBuddyGPT/usecases/web_api_testing/utils/__init__.py‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎src/hackingBuddyGPT/usecases/web_api_testing/utils/configuration_handler.py‎

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎src/hackingBuddyGPT/utils/prompt_generation/prompts/task_planning/tree_of_thought_prompt.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from hackingBuddyGPT.utils.prompt_generation.prompts.task_planning import (
99
TaskPlanningPrompt,
1010
)
11-
from hackingBuddyGPT.usecases.web_api_testing.utils.custom_datatypes import Prompt
11+
from hackingBuddyGPT.utils.web_api.custom_datatypes import Prompt
1212

1313

1414
class TreeOfThoughtPrompt(TaskPlanningPrompt):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from hackingBuddyGPT.utils.prompt_generation.information import (
1111
PromptPurpose,
1212
)
13-
from hackingBuddyGPT.usecases.web_api_testing.utils import LLMHandler
13+
from hackingBuddyGPT.utils.web_api.llm_handler import LLMHandler
1414
from hackingBuddyGPT.utils import tool_message
1515

1616

‎src/hackingBuddyGPT/usecases/web_api_testing/utils/response_handler.py‎ renamed to ‎src/hackingBuddyGPT/utils/web_api/response_handler.py‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
from hackingBuddyGPT.utils.web_api.pattern_matcher import PatternMatcher
1313
from hackingBuddyGPT.utils.prompt_generation.prompt_generation_helper import PromptGenerationHelper
1414
from hackingBuddyGPT.utils.prompt_generation.information import PromptContext
15-
from hackingBuddyGPT.utils.prompt_generation.information import (
16-
PenTestingInformation,
17-
)
18-
from hackingBuddyGPT.usecases.web_api_testing.utils.response_analyzer_with_llm import (
19-
ResponseAnalyzerWithLLM,
20-
)
21-
from hackingBuddyGPT.usecases.web_api_testing.utils import LLMHandler
22-
from hackingBuddyGPT.usecases.web_api_testing.utils.custom_datatypes import Prompt
15+
from hackingBuddyGPT.utils.prompt_generation.information import PenTestingInformation
16+
from hackingBuddyGPT.utils.web_api.response_analyzer_with_llm import ResponseAnalyzerWithLLM
17+
from hackingBuddyGPT.utils.web_api.llm_handler import LLMHandler
18+
from hackingBuddyGPT.utils.web_api.custom_datatypes import Prompt
2319
from hackingBuddyGPT.utils import tool_message
2420

2521

0 commit comments

Comments
 (0)