Added:
trunk/MySql.Web/Tests/
trunk/MySql.Web/Tests/App.config
trunk/MySql.Web/Tests/BaseTest.cs
trunk/MySql.Web/Tests/MySql.Web.Tests.csproj
trunk/MySql.Web/Tests/Properties/
trunk/MySql.Web/Tests/Properties/AssemblyInfo.cs
trunk/MySql.Web/Tests/SchemaTests.cs
trunk/MySql.Web/Tests/UserManagement.cs
Log:
Unit testing framework for the web providers
Added: trunk/MySql.Web/Tests/App.config
===================================================================
--- trunk/MySql.Web/Tests/App.config 2007-06-21 15:34:29 UTC (rev 769)
+++ trunk/MySql.Web/Tests/App.config 2007-06-21 17:11:34 UTC (rev 770)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <connectionStrings>
+ <remove name="LocalMySqlServer"/>
+ <add name="LocalMySqlServer" connectionString="server=localhost;uid=root;database=test;pooling=false"/>
+ </connectionStrings>
+ <system.web>
+ <membership defaultProvider="MySQLMembershipProvider">
+ <providers>
+ <remove name="MySQLMembershipProvider"/>
+ <add name="MySQLMembershipProvider"
+ type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=5.1.2.2, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
+ connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false"
+ enablePasswordReset="true" requiresQuestionAndAnswer="true"
+ applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed"
+ maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7"
+ minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"
+ passwordStrengthRegularExpression=""/>
+ </providers>
+ </membership>
+ </system.web>
+</configuration>
\ No newline at end of file
Added: trunk/MySql.Web/Tests/BaseTest.cs
===================================================================
--- trunk/MySql.Web/Tests/BaseTest.cs 2007-06-21 15:34:29 UTC (rev 769)
+++ trunk/MySql.Web/Tests/BaseTest.cs 2007-06-21 17:11:34 UTC (rev 770)
@@ -0,0 +1,67 @@
+// Copyright (C) 2007 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// This code was contributed by Sean Wright (srwright@stripped) on 2007-01-12
+// The copyright was assigned and transferred under the terms of
+// the MySQL Contributor License Agreement (CLA)
+
+using NUnit.Framework;
+using MySql.Data.MySqlClient;
+using System.Data;
+using System.Configuration;
+
+namespace MySql.Web.Security.Tests
+{
+ public class BaseTest
+ {
+ protected MySqlConnection connection;
+
+ [TestFixtureSetUp]
+ public virtual void TestFixtureSetUp()
+ {
+ string connStr = ConfigurationManager.ConnectionStrings["LocalMySqlServer"].ConnectionString;
+ connection = new MySqlConnection(connStr);
+ connection.Open();
+ }
+
+ [TestFixtureTearDown]
+ public virtual void TestFixtureTearDown()
+ {
+ if (connection != null &&
+ connection.State == ConnectionState.Open)
+ connection.Close();
+ connection = null;
+ }
+
+ protected void execSQL(string sql)
+ {
+ MySqlCommand cmd = new MySqlCommand(sql, connection);
+ cmd.ExecuteNonQuery();
+ }
+
+ protected DataTable GetMembers()
+ {
+ MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM mysql_membership", connection);
+ DataTable dt = new DataTable();
+ da.Fill(dt);
+ return dt;
+ }
+ }
+}
Added: trunk/MySql.Web/Tests/MySql.Web.Tests.csproj
===================================================================
--- trunk/MySql.Web/Tests/MySql.Web.Tests.csproj 2007-06-21 15:34:29 UTC (rev 769)
+++ trunk/MySql.Web/Tests/MySql.Web.Tests.csproj 2007-06-21 17:11:34 UTC (rev 770)
@@ -0,0 +1,65 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{DC704374-EC50-4167-93AA-8D262136502E}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>MySql.Web.Tests</RootNamespace>
+ <AssemblyName>MySql.Web.Tests</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="nunit.framework, Version=2.4.1.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+ <Reference Include="System" />
+ <Reference Include="System.configuration" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="BaseTest.cs" />
+ <Compile Include="SchemaTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="UserManagement.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\Driver\MySql.Data.csproj">
+ <Project>{E9DF5ED1-4CBD-4226-B931-9A51610AC14D}</Project>
+ <Name>MySql.Data</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Providers\MySql.Web.csproj">
+ <Project>{C28B1166-1380-445D-AEC1-8A18B990DD18}</Project>
+ <Name>MySql.Web</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
Added: trunk/MySql.Web/Tests/Properties/AssemblyInfo.cs
===================================================================
--- trunk/MySql.Web/Tests/Properties/AssemblyInfo.cs 2007-06-21 15:34:29 UTC (rev 769)
+++ trunk/MySql.Web/Tests/Properties/AssemblyInfo.cs 2007-06-21 17:11:34 UTC (rev 770)
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("MySql.Web.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("MySQL AB")]
+[assembly: AssemblyProduct("MySql.Web.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2004-2007, MySQL AB")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("5ea74c78-c679-464f-99ba-ae1b0b54550b")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("5.1.3")]
+[assembly: AssemblyFileVersion("5.1.3")]
Added: trunk/MySql.Web/Tests/SchemaTests.cs
===================================================================
--- trunk/MySql.Web/Tests/SchemaTests.cs 2007-06-21 15:34:29 UTC (rev 769)
+++ trunk/MySql.Web/Tests/SchemaTests.cs 2007-06-21 17:11:34 UTC (rev 770)
@@ -0,0 +1,113 @@
+// Copyright (C) 2007 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// This code was contributed by Sean Wright (srwright@stripped) on 2007-01-12
+// The copyright was assigned and transferred under the terms of
+// the MySQL Contributor License Agreement (CLA)
+
+using NUnit.Framework;
+using MySql.Web.Security;
+using System.Collections.Specialized;
+using MySql.Data.MySqlClient;
+
+namespace MySql.Web.Security.Tests
+{
+ [TestFixture]
+ public class SchemaTests : BaseTest
+ {
+ [SetUp]
+ public void Setup()
+ {
+ execSQL("DROP TABLE IF EXISTS mysql_Membership");
+ execSQL("DROP TABLE IF EXISTS mysql_Roles");
+ execSQL("DROP TABLE IF EXISTS mysql_UsersInRoles");
+ }
+
+ [Test]
+ public void CurrentSchema()
+ {
+ MySQLMembershipProvider provider = new MySQLMembershipProvider();
+ NameValueCollection config = new NameValueCollection();
+ config.Add("connectionStringName", "LocalMySqlServer");
+ provider.Initialize(null, config);
+
+ MySqlCommand cmd = new MySqlCommand("SHOW CREATE TABLE mysql_membership", connection);
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ string createTable = reader.GetString(1);
+ int index = createTable.IndexOf("COMMENT='2'");
+ Assert.AreNotEqual(-1, index);
+ }
+ }
+
+ [Test]
+ public void UpgradeV1ToV2()
+ {
+ execSQL(schema1);
+
+ MySQLMembershipProvider provider = new MySQLMembershipProvider();
+ NameValueCollection config = new NameValueCollection();
+ config.Add("connectionStringName", "LocalMySqlServer");
+ provider.Initialize(null, config);
+
+ MySqlCommand cmd = new MySqlCommand("SHOW CREATE TABLE mysql_membership", connection);
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ string createTable = reader.GetString(1);
+ int index = createTable.IndexOf("COMMENT='2'");
+ Assert.AreNotEqual(-1, index);
+ }
+ }
+
+ #region Schema
+
+ private const string schema1 =
+ @"CREATE TABLE mysql_Membership(`PKID` varchar(36) NOT NULL,
+ `Username` varchar(255) NOT NULL,
+ `ApplicationName` varchar(255) NOT NULL,
+ `Email` varchar(128) NOT NULL,
+ `Comment` varchar(255) default NULL,
+ `Password` varchar(128) NOT NULL,
+ `PasswordQuestion` varchar(255) default NULL,
+ `PasswordAnswer` varchar(255) default NULL,
+ `IsApproved` tinyint(1) default NULL,
+ `LastActivityDate` datetime default NULL,
+ `LastLoginDate` datetime default NULL,
+ `LastPasswordChangedDate` datetime default NULL,
+ `CreationDate` datetime default NULL,
+ `IsOnline` tinyint(1) default NULL,
+ `IsLockedOut` tinyint(1) default NULL,
+ `LastLockedOutDate` datetime default NULL,
+ `FailedPasswordAttemptCount` int(10) unsigned default NULL,
+ `FailedPasswordAttemptWindowStart` datetime default NULL,
+ `FailedPasswordAnswerAttemptCount` int(10) unsigned default NULL,
+ `FailedPasswordAnswerAttemptWindowStart` datetime default NULL,
+ PRIMARY KEY (`PKID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='1'";
+
+ private const string schema2 =
+ @"ALTER TABLE mysql_Membership
+ ADD COLUMN PasswordKey char(16) AFTER Password,
+ ADD COLUMN PasswordFormat tinyint AFTER PasswordKey, COMMENT='2'";
+
+ #endregion
+ }
+}
Added: trunk/MySql.Web/Tests/UserManagement.cs
===================================================================
--- trunk/MySql.Web/Tests/UserManagement.cs 2007-06-21 15:34:29 UTC (rev 769)
+++ trunk/MySql.Web/Tests/UserManagement.cs 2007-06-21 17:11:34 UTC (rev 770)
@@ -0,0 +1,68 @@
+// Copyright (C) 2007 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// This code was contributed by Sean Wright (srwright@stripped) on 2007-01-12
+// The copyright was assigned and transferred under the terms of
+// the MySQL Contributor License Agreement (CLA)
+
+using NUnit.Framework;
+using System.Web.Security;
+using System.Collections.Specialized;
+using System.Data;
+using System;
+
+namespace MySql.Web.Security.Tests
+{
+ [TestFixture]
+ public class UserManagement : BaseTest
+ {
+ private MySQLMembershipProvider provider;
+
+ [SetUp]
+ public void SetUp()
+ {
+ execSQL("TRUNCATE TABLE mysql_Membership");
+ }
+
+ [Test]
+ public void CreateUserWithHashedPassword()
+ {
+ provider = new MySQLMembershipProvider();
+ NameValueCollection config = new NameValueCollection();
+ config.Add("connectionStringName", "LocalMySqlServer");
+ config.Add("applicationName", "/");
+ provider.Initialize(null, config);
+
+ // create the user
+ MembershipCreateStatus status;
+ provider.CreateUser("foo", "bar", "foo@stripped", null, null, true, null, out status);
+ Assert.AreEqual(MembershipCreateStatus.Success, status);
+
+ // verify that the password format is hashed.
+ DataTable table = GetMembers();
+ MembershipPasswordFormat format =
+ (MembershipPasswordFormat)Convert.ToInt32(table.Rows[0]["PasswordFormat"]);
+ Assert.AreEqual(MembershipPasswordFormat.Hashed, format);
+
+ // then attempt to verify the user
+ provider.ValidateUser("foo", "bar");
+ }
+ }
+}
| Thread |
|---|
| • Connector/NET commit: r770 - in trunk/MySql.Web: . Tests Tests/Properties | rburnett | 21 Jun |