Check that zipped folder name is in correct format.

This commit is contained in:
NissimHadar 2019-02-13 15:18:07 -08:00
parent 86aaba016f
commit 56483f4884
2 changed files with 24 additions and 5 deletions

View file

@ -27,9 +27,29 @@ void AWSInterface::createWebPageFromResults(const QString& testResults,
const QString& workingDirectory,
QCheckBox* updateAWSCheckBox,
QLineEdit* urlLineEdit) {
_testResults = testResults;
_workingDirectory = workingDirectory;
// Verify filename is in correct format
// For example `D:/tt/TestResults--2019-02-10_17-30-57(local)[DESKTOP-6BO62Q9].zip`
QStringList parts = testResults.split('/');
QString zipFilename = parts[parts.length() - 1];
_zipFolderName = _workingDirectory + "/" + zipFilename.split('.')[0];
QStringList zipFolderNameParts = zipFilename.split(QRegExp("[\\(\\)\\[\\]]"), QString::SkipEmptyParts);
bool a = QRegularExpression("TestResults--\\d{4}(-\\d\\d){2}_\\d\\d(-\\d\\d){2}").match(zipFolderNameParts[0]).hasMatch();
bool b = QRegularExpression("\\w").match(zipFolderNameParts[1]).hasMatch();
bool c = QRegularExpression("\\w").match(zipFolderNameParts[2]).hasMatch();
if (!QRegularExpression("TestResults--\\d{4}(-\\d\\d){2}_\\d\\d(-\\d\\d){2}").match(zipFolderNameParts[0]).hasMatch() ||
!QRegularExpression("\\w").match(zipFolderNameParts[1]).hasMatch() || // build (local, build number or PR number)
!QRegularExpression("\\w").match(zipFolderNameParts[2]).hasMatch() // machine name
) {
QMessageBox::critical(0, "Filename is in wrong format", "'" + zipFilename + "' is not in nitpick format");
return;
}
_testResults = testResults;
_urlLineEdit = urlLineEdit;
_urlLineEdit->setEnabled(false);
@ -48,10 +68,8 @@ void AWSInterface::extractTestFailuresFromZippedFolder() {
// For a test results zip file called `D:/tt/TestResults--2018-10-02_16-54-11(9426)[DESKTOP-PMKNLSQ].zip`
// the folder will be called `TestResults--2018-10-02_16-54-11(9426)[DESKTOP-PMKNLSQ]`
// and, this folder will be in the working directory
QStringList parts = _testResults.split('/');
QString zipFolderName = _workingDirectory + "/" + parts[parts.length() - 1].split('.')[0];
if (QDir(zipFolderName).exists()) {
QDir dir = zipFolderName;
if (QDir(_zipFolderName).exists()) {
QDir dir = _zipFolderName;
dir.removeRecursively();
}

View file

@ -49,6 +49,7 @@ public:
private:
QString _testResults;
QString _zipFolderName;
QString _workingDirectory;
QString _resultsFolder;
QString _htmlFailuresFolder;