108 lines
3.9 KiB
Dart
108 lines
3.9 KiB
Dart
|
import 'dart:io';
|
||
|
import 'package:xml/xml.dart';
|
||
|
import 'package:faker/faker.dart';
|
||
|
import 'login-and-register.dart';
|
||
|
|
||
|
const int NUM_LOGIN_TESTS = 100;
|
||
|
const int NUM_REGISTRATION_TESTS = 100;
|
||
|
|
||
|
|
||
|
List<XmlElement> fuzzTestLogin(int numTests) {
|
||
|
final faker = Faker(); // Utwórz instancję Faker
|
||
|
List<XmlElement> loginResults = [];
|
||
|
|
||
|
for (int i = 0; i < numTests; i++) {
|
||
|
String email = faker.internet.email(); // Wygenreuj losowy email
|
||
|
String password = faker.internet.password(); // Wygeneruj losowe hasło
|
||
|
|
||
|
print('Test $i: Attempting login with Email: $email, Password: $password');
|
||
|
try {
|
||
|
login(email, password);
|
||
|
print('Login successful');
|
||
|
loginResults.add(XmlElement(XmlName('loginResult'), [], [
|
||
|
XmlElement(XmlName('test'), [], [
|
||
|
XmlElement(XmlName('email'), [], [XmlText(email)]),
|
||
|
XmlElement(XmlName('password'), [], [XmlText(password)]),
|
||
|
XmlElement(XmlName('status'), [], [XmlText('success')])
|
||
|
])
|
||
|
]));
|
||
|
} catch (e) {
|
||
|
print('Login failed: $e');
|
||
|
loginResults.add(XmlElement(XmlName('loginResult'), [], [
|
||
|
XmlElement(XmlName('test'), [], [
|
||
|
XmlElement(XmlName('email'), [], [XmlText(email)]),
|
||
|
XmlElement(XmlName('password'), [], [XmlText(password)]),
|
||
|
XmlElement(XmlName('status'), [], [XmlText('failed: $e')])
|
||
|
])
|
||
|
]));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return loginResults;
|
||
|
}
|
||
|
|
||
|
List<XmlElement> fuzzTestRegister(int numTests) {
|
||
|
final faker = Faker(); // Utwórz instancję Faker
|
||
|
List<XmlElement> registrationResults = [];
|
||
|
|
||
|
for (int i = 0; i < numTests; i++) {
|
||
|
String name = faker.person.firstName();
|
||
|
String surname = faker.person.lastName();
|
||
|
String email = faker.internet.email();
|
||
|
String phone =
|
||
|
faker.randomGenerator.integer(100000000, min: 100000000).toString();
|
||
|
String password = faker.internet.password();
|
||
|
|
||
|
print(
|
||
|
'Test $i: Attempting register with Name: $name, Surname: $surname, Email: $email, Phone: $phone, Password: $password');
|
||
|
try {
|
||
|
register(name, surname, email, phone, password);
|
||
|
print('Registration successful');
|
||
|
registrationResults.add(XmlElement(XmlName('registrationResult'), [], [
|
||
|
XmlElement(XmlName('test'), [], [
|
||
|
XmlElement(XmlName('name'), [], [XmlText(name)]),
|
||
|
XmlElement(XmlName('surname'), [], [XmlText(surname)]),
|
||
|
XmlElement(XmlName('email'), [], [XmlText(email)]),
|
||
|
XmlElement(XmlName('phone'), [], [XmlText(phone)]),
|
||
|
XmlElement(XmlName('password'), [], [XmlText(password)]),
|
||
|
XmlElement(XmlName('status'), [], [XmlText('success')])
|
||
|
])
|
||
|
]));
|
||
|
} catch (e) {
|
||
|
print('Registration failed: $e');
|
||
|
registrationResults.add(XmlElement(XmlName('registrationResult'), [], [
|
||
|
XmlElement(XmlName('test'), [], [
|
||
|
XmlElement(XmlName('name'), [], [XmlText(name)]),
|
||
|
XmlElement(XmlName('surname'), [], [XmlText(surname)]),
|
||
|
XmlElement(XmlName('email'), [], [XmlText(email)]),
|
||
|
XmlElement(XmlName('phone'), [], [XmlText(phone)]),
|
||
|
XmlElement(XmlName('password'), [], [XmlText(password)]),
|
||
|
XmlElement(XmlName('status'), [], [XmlText('failed: $e')])
|
||
|
])
|
||
|
]));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return registrationResults;
|
||
|
}
|
||
|
|
||
|
void main() {
|
||
|
List<XmlElement> loginResults = fuzzTestLogin(NUM_LOGIN_TESTS);
|
||
|
List<XmlElement> registrationResults =
|
||
|
fuzzTestRegister(NUM_REGISTRATION_TESTS);
|
||
|
|
||
|
// Creating the XML document
|
||
|
final builder = XmlBuilder();
|
||
|
builder.processing('xml', 'version="1.0"');
|
||
|
builder.element('fuzzTestingResults', nest: () {
|
||
|
builder.element('loginTests', nest: loginResults);
|
||
|
builder.element('registrationTests', nest: registrationResults);
|
||
|
});
|
||
|
|
||
|
final document = builder.buildDocument();
|
||
|
final xmlString = document.toXmlString(pretty: true, indent: ' ');
|
||
|
// Zapis do pliku xml
|
||
|
File('fuzz_testing_results.xml').writeAsStringSync(xmlString);
|
||
|
print('Results have been written to fuzz_testing_results.xml');
|
||
|
}
|