Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for the remaining features and the new features added #428

Merged
merged 8 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions lib/src/pages/drawer/projects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,17 @@ class _ProjectSectionState extends State<ProjectSection> {
),
),
SizedBox(width: 5),
Text(
widget.project.name,
softWrap: true,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.ubuntu(
textStyle: TextStyle(
color: Color(0xFFDC4654),
fontSize: 20,
fontWeight: FontWeight.bold,
SizedBox(
width: size.width * 0.8,
child: Text(
widget.project.name,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.ubuntu(
textStyle: TextStyle(
color: Color(0xFFDC4654),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
Expand Down
7 changes: 5 additions & 2 deletions lib/src/util/api/project_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import '../util_import.dart';
class ProjectAPiClient {
ProjectAPiClient._();

static Future<List<Project>?> getAllProjects() async {
static Future<List<Project>?> getAllProjects(
{http.Client? testClient}) async {
List<Project> projects = [];
try {
var uri = GeneralEndPoints.apiBaseUrl + "projects/";
var response = await http.get(Uri.parse(uri));
var response = (testClient != null)
? await testClient.get(Uri.parse(uri))
: await http.get(Uri.parse(uri));
var json_res = json.decode(response.body);
projects = Project.fromSnapshot(json_res['projects']);
} catch (e) {
Expand Down
118 changes: 118 additions & 0 deletions test/unit_tests/bug_hunt_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import 'package:http/http.dart' as http;
import '../test_imports.dart';

void main() {
final mockRespUP = [
{
"id": 2,
"name": "Mobile App Functionality",
"url": "http://www.testhunt2.com",
"prize": 5,
"logo": "logos.png",
"banner": "",
"description":
"Objective:\r\nIdentify and report functionality and performance issues in the organization's newly launched mobile app, ensuring it provides a smooth and bug-free user experience.\r\n\r\nScope:\r\n\r\nTest the app on various devices and operating systems (iOS and Android).\r\nCheck for UI/UX inconsistencies, crashes, and unexpected behaviors.\r\nEvaluate app performance under different network conditions.\r\nTest all features, including push notifications, in-app purchases, and data synchronization.\r\nTools:\r\n\r\nAppium\r\nTestComplete\r\nFirebase Test Lab\r\nRewards:\r\nParticipants will receive points for each valid bug report, which can be redeemed for gift cards, app credits, or exclusive access to future app updates and beta versions.",
"starts_on": "2024-07-18T16:03:51Z",
"end_on": "2024-07-27T16:03:54Z"
},
{
"id": 1,
"name": "API Security",
"url": "http://hunt-new.com",
"prize": 10,
"logo": "logos.png",
"banner": "banners.png",
"description":
"Objective:\r\nIdentify and report security vulnerabilities and functionality issues in the organization's public APIs to ensure they are secure, reliable, and perform as expected.\r\n\r\nScope:\r\n\r\nTest API endpoints for security vulnerabilities such as unauthorized access, data leakage, and input validation issues.\r\nEvaluate API performance under load and stress conditions.\r\nEnsure proper error handling and response codes.\r\nCheck for compliance with API documentation and expected functionality.\r\nTools:\r\n\r\nPostman\r\nInsomnia\r\nJMeter\r\nRewards:\r\nParticipants will be rewarded with bounty points based on the severity of the discovered issues. Top contributors will receive special recognition, monetary rewards, and opportunities for collaboration with the organization's development team.",
"starts_on": "2024-07-09T09:06:24Z",
"end_on": "2024-07-26T09:06:30Z"
},
];
final mockResp = [
{
"id": 1,
"name": "Application Vulnerability",
"url": "http://www.test.com",
"prize": 2,
"logo": "logos.jpg",
"banner": "banners.png",
"description":
"Objective:\r\nIdentify and report security vulnerabilities in the organization's web application, focusing on potential threats such as SQL injection, cross-site scripting (XSS), and broken authentication.\r\n\r\nScope:\r\n\r\nTest all user input fields, including login forms, search bars, and data submission fields.\r\nAssess session management and authentication mechanisms.\r\nEvaluate access controls and permissions.\r\nCheck for outdated libraries and dependencies.\r\nTools:\r\n\r\nBurp Suite\r\nOWASP ZAP\r\nSQLMap\r\nRewards:\r\nParticipants will be rewarded based on the severity and impact of the discovered vulnerabilities. Rewards include cash prizes, recognition in the organization's Hall of Fame, and exclusive swag.",
"starts_on": "2024-07-01T18:17:13Z",
"end_on": "2024-04-02T18:17:16Z"
}
];
group("Bug Hunt API's Test", () {
test("Get List of Upcomming Bug Hunts", () async {
final client = MockClient((response) async {
final response = mockRespUP;
return http.Response(jsonEncode(response), 200);
});
final response =
await BugHuntApiClient.getListOfUpcomingBugHunts(client: client);
expect(response.length, 2);
expect(response[0].name, "Mobile App Functionality");
expect(response[0].url, "http://www.testhunt2.com");
expect(response[0].prize, 5);
expect(response[1].name, "API Security");
expect(response[1].url, "http://hunt-new.com");
expect(response[1].prize, 10);
});

test("Get List of Previous Bug Hunts", () async {
final client = MockClient((response) async {
final response = mockResp;
return http.Response(jsonEncode(response), 200);
});
final response =
await BugHuntApiClient.getListOfPreviousBugHunts(client: client);
expect(response.length, 1);
expect(response[0].name, "Application Vulnerability");
expect(response[0].url, "http://www.test.com");
expect(response[0].prize, 2);
});
test("Get List of Active Bug Hunts", () async {
final String url = GeneralEndPoints.apiBaseUrl + "/hunt/?activeHunt=true";
final client = MockClient((response) async {
final response = mockResp;
return http.Response(jsonEncode(response), 200);
});
final response = await client.get(Uri.parse(url));
var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes));
List<BugHunt> bugHuntList = BugHunt.fromSnapshot(decodedResponse);
expect(bugHuntList.length, 1);
expect(bugHuntList[0].name, "Application Vulnerability");
expect(bugHuntList[0].url, "http://www.test.com");
expect(bugHuntList[0].prize, 2);
});

test("Get List of Active and Upcomming Bug Hunts", () async {
final urlToResponseMap = {
GeneralEndPoints.apiBaseUrl + "/hunt/?activeHunt=true": mockResp,
GeneralEndPoints.apiBaseUrl + "/hunt/?upcomingHunt=true": mockRespUP,
};

// Create the mock client
final client = MockClient((request) async {
final response = urlToResponseMap[request.url.toString()];
if (response != null) {
return http.Response(jsonEncode(response), 200);
} else {
return http.Response('Not Found', 404);
}
});
final response =
await BugHuntApiClient.getListOfActiveBugHunts(client: client);
expect(response.length, 3);
expect(response[0].name, "Application Vulnerability");
expect(response[0].url, "http://www.test.com");
expect(response[0].prize, 2);
expect(response[1].name, "Mobile App Functionality");
expect(response[1].url, "http://www.testhunt2.com");
expect(response[1].prize, 5);
expect(response[2].name, "API Security");
expect(response[2].url, "http://hunt-new.com");
expect(response[2].prize, 10);
});
});
}
61 changes: 61 additions & 0 deletions test/unit_tests/project_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:blt/src/util/api/project_apis.dart';
import 'package:http/http.dart' as http;
import '../test_imports.dart';

void main() {
group("Project Api's Test", () {
test("get all projects", () async {
final dynamic mockResponse = {
"count": 1,
"projects": [
{
"id": 13,
"name": "TestProject",
"slug": "testproject",
"description": "Test Project",
"github_url": "https://github.com/Test/test",
"wiki_url": "",
"homepage_url": "",
"logo_url": "https://test.org/www-test-test/test/test/test.png",
"created": "2024-07-16T19:08:44.846535Z",
"modified": "2024-08-02T14:53:41.131125Z",
"contributors": [
{
"id": 00,
"name": "cont1",
"github_id": 000111,
"github_url": "https://github.com/cont1",
"avatar_url": "https://avatars.githubusercontent.com/u/cont1",
"contributor_type": "User",
"contributions": 2,
"created": "2024-08-04T19:03:52.956106Z"
},
{
"id": 01,
"name": "bot[bot]",
"github_id": 002200,
"github_url": "https://github.com/BOT/bot",
"avatar_url": "https://avatars.githubusercontent.com/in/bot",
"contributor_type": "Bot",
"contributions": 1,
"created": "2024-08-04T19:03:52.956106Z"
},
]
}
]
};
final client = MockClient((request) async {
final response = mockResponse;
return http.Response(jsonEncode(response), 200);
});
final result = await ProjectAPiClient.getAllProjects(testClient: client);
expect(result?.length, 1);
expect(result?[0].contributors?.length, 2);
expect(result?[0].name, 'TestProject');
expect(result?[0].contributors?[0].name, "cont1");
expect(result?[0].contributors?[0].contributions, 2);
expect(result?[0].contributors?[1].name, "bot[bot]");
expect(result?[0].contributors?[1].contributions, 1);
});
});
}
Loading