Install with database permissions check WORKS. Preparing to install live hosted server.

This commit is contained in:
Rick Falkvinge
2014-09-08 13:57:45 +00:00
parent 377905c6e6
commit ac461a8d03
7 changed files with 390 additions and 41 deletions
+12
View File
@@ -30,6 +30,18 @@ namespace Swarmops.Database
return new SwarmDb(ConstructConnectString(new Configuration().Get().Admin));
}
public static SwarmDb GetTestDatabase(Credentials credentials)
{
// For security reasons, this function is only available BEFORE the database has been initialized.
if (Configuration.IsConfigured())
{
throw new UnauthorizedAccessException("Cannot probe arbitrary database credentials once database initialized");
}
return new SwarmDb(ConstructConnectString(credentials));
}
private static string ConstructConnectString (Credentials credentials)
{
return "server=" + credentials.ServerSet.ServerPriorities[0].Split(';')[0] + ";database=" + credentials.Database +
+200
View File
@@ -0,0 +1,200 @@
using System;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Swarmops.Database
{
public partial class SwarmDb
{
public bool TestLogin()
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
return true;
}
}
catch (Exception)
{
return false;
}
}
public bool TestCreateTable()
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand(
"CREATE TABLE `CredentialsTests` (" +
" `TestId` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT," +
" `Description` VARCHAR(256) NOT NULL," +
" `DateTimeCreated` DATETIME NOT NULL," +
" PRIMARY KEY (`TestId`)" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='This table is created to test database credentials'", connection);
command.ExecuteNonQuery();
return true;
}
}
catch (Exception debug)
{
Debug.WriteLine(debug.ToString());
return false;
}
}
public bool TestAlterTable()
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand(
"ALTER TABLE `CredentialsTests` ADD COLUMN `AppendedColumn` INT AFTER `DateTimeCreated`", connection);
command.ExecuteNonQuery();
return true;
}
}
catch (Exception debug)
{
Debug.WriteLine(debug.ToString());
return false;
}
}
public bool TestDropTable()
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand(
"DROP TABLE `CredentialsTests`", connection);
command.ExecuteNonQuery();
return true;
}
}
catch (Exception debug)
{
Debug.WriteLine(debug.ToString());
return false;
}
}
public bool TestCreateProcedure()
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand(
"CREATE PROCEDURE `CreateCredentialsTest`(" +
" description VARCHAR(128)" +
")" +
"BEGIN" +
"" +
" INSERT INTO CredentialsTests (Description,DateTimeCreated)" +
" VALUES(description, NOW());" +
" " +
"END", connection);
command.ExecuteNonQuery();
return true;
}
}
catch (Exception debug)
{
Debug.WriteLine(debug.ToString());
return false;
}
}
public bool TestDropProcedure()
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand(
"DROP PROCEDURE `CreateCredentialsTest`", connection);
command.ExecuteNonQuery();
return true;
}
}
catch (Exception debug)
{
Debug.WriteLine(debug.ToString());
return false;
}
}
public bool TestExecute(string testDescription)
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("CreateCredentialsTest", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "description", testDescription);
command.ExecuteNonQuery();
return true;
}
}
catch (Exception debug)
{
Debug.WriteLine(debug.ToString());
return false;
}
}
public bool TestSelect()
{
try
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand(
"SELECT * FROM CredentialsTests", connection);
DbDataReader reader = command.ExecuteReader();
return true;
}
}
catch (Exception debug)
{
Debug.WriteLine(debug.ToString());
return false;
}
}
}
}
+1
View File
@@ -124,6 +124,7 @@
<Compile Include="Database-SwarmopsLog.cs" />
<Compile Include="Database-TaxLevels.cs" />
<Compile Include="Database-TemporaryIdentities.cs" />
<Compile Include="Database-Tests.cs" />
<Compile Include="Database-UrlTranslations.cs" />
<Compile Include="Database-Volunteers.cs" />
<Compile Include="Database-Permissions.cs" />