Added error handling if cookie retrieval fails

This commit is contained in:
2023-05-30 10:26:04 +02:00
parent 067e7233a0
commit 991800728e
4 changed files with 43 additions and 25 deletions
+26 -23
View File
@@ -66,36 +66,38 @@ namespace Test_Merge
StartCookieRecovering();
string value = "";
List<Cookie> cookies = new List<Cookie>();
using (var reader = new StreamReader(COOKIES_CSV_FILENAME))
if (File.Exists(COOKIES_CSV_FILENAME))
{
// Read the header row and validate column order
string header = reader.ReadLine();
string[] expectedColumns = { "host_key", "name", "value", "path", "expires_utc", "is_secure", "is_httponly" };
string[] actualColumns = header.Split(',');
for (int i = 0; i < expectedColumns.Length; i++)
using (var reader = new StreamReader(COOKIES_CSV_FILENAME))
{
if (expectedColumns[i] != actualColumns[i])
// Read the header row and validate column order
string header = reader.ReadLine();
string[] expectedColumns = { "host_key", "name", "value", "path", "expires_utc", "is_secure", "is_httponly" };
string[] actualColumns = header.Split(',');
for (int i = 0; i < expectedColumns.Length; i++)
{
throw new InvalidOperationException($"Expected column '{expectedColumns[i]}' at index {i} but found '{actualColumns[i]}'");
if (expectedColumns[i] != actualColumns[i])
{
throw new InvalidOperationException($"Expected column '{expectedColumns[i]}' at index {i} but found '{actualColumns[i]}'");
}
}
}
// Read each data row and parse values into a Cookie object
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
string[] fields = line.Split(',');
string hostname = fields[0];
string cookieName = fields[1];
if (hostname == host && cookieName == name)
// Read each data row and parse values into a Cookie object
while (!reader.EndOfStream)
{
value = fields[2];
string line = reader.ReadLine();
string[] fields = line.Split(',');
string hostname = fields[0];
string cookieName = fields[1];
if (hostname == host && cookieName == name)
{
value = fields[2];
}
}
}
}
return value;
}
/// <summary>
@@ -111,8 +113,9 @@ namespace Test_Merge
string loginCookieValue = GetCookie(COOKIE_HOST, loginCookieName);
string loginSessionValue = GetCookie(COOKIE_HOST, loginSessionCookieName);
int windowWidth = 1920;
int windowHeight = 768;
//Cookie retreival has gone wrong (usually its because of python not being installed properly)
if (loginCookieValue == "" || loginSessionValue == "")
return 100;
var service = FirefoxDriverService.CreateDefaultService(GECKODRIVER_FILENAME);
service.Host = "127.0.0.1";