Example #1
0
        public void TestFreakyPasswordValues(string freakyPassword)
        {
            //cleanup
            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(c => c.Name.Equals("frankieFran")))
            {
                c.DeleteInDatabase();
            }

            DataAccessCredentials creds = new DataAccessCredentials(CatalogueRepository, "frankieFran");

            try
            {
                //as soon as you set a password it should be encrypted by the credentials class in memory
                creds.Password = freakyPassword;
                Assert.AreNotEqual(freakyPassword, creds.Password);
                Assert.AreEqual(freakyPassword, creds.GetDecryptedPassword());//but we should still be able to decrypt it

                //save it
                creds.SaveToDatabase();
                using (var con = CatalogueRepository.GetConnection())
                {
                    string value;
                    using (var cmd = DatabaseCommandHelper.GetCommand("Select Password from DataAccessCredentials where Name='frankieFran'", con.Connection, con.Transaction))
                        value = (string)cmd.ExecuteScalar();

                    //ensure password in database is encrypted
                    Assert.AreNotEqual(freakyPassword, value);
                    Assert.AreEqual(creds.Password, value);//does value in database match value in memory (encrypted)
                }

                //get a new copy out of the database
                DataAccessCredentials newCopy = CatalogueRepository.GetObjectByID <DataAccessCredentials>(creds.ID);
                Assert.AreEqual(creds.Password, newCopy.Password);  //passwords should match
                Assert.AreNotEqual(freakyPassword, creds.Password); //neither should be fish
                Assert.AreNotEqual(freakyPassword, newCopy.Password);

                //both should decrypt to the same value (fish
                Assert.AreEqual(freakyPassword, creds.GetDecryptedPassword());
                Assert.AreEqual(freakyPassword, newCopy.GetDecryptedPassword());
            }
            finally
            {
                creds.DeleteInDatabase();
            }
        }
Example #2
0
        public void GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride()
        {
            Catalogue     c   = new Catalogue(CatalogueRepository, "GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride");
            CatalogueItem ci  = new CatalogueItem(CatalogueRepository, c, "GetConnectionStringFromCatalogueWhereOneTableInfoUsesACredentialsOverride");
            TableInfo     t   = new TableInfo(CatalogueRepository, "Test");
            ColumnInfo    col = new ColumnInfo(CatalogueRepository, "[mydatabase].dbo.test.col", "varchar(10)", t);

            var extractionInformation = new ExtractionInformation(CatalogueRepository, ci, col, col.Name);

            DataAccessCredentials cred = null;

            try
            {
                t.Server   = "myserver";
                t.Database = "mydatabase";

                cred          = new DataAccessCredentials(CatalogueRepository, "bob");
                cred.Username = "******";
                cred.Password = "******";

                Assert.AreNotEqual("pass", cred.Password);
                Assert.AreEqual("pass", cred.GetDecryptedPassword());


                cred.SaveToDatabase();
                t.SetCredentials(cred, DataAccessContext.InternalDataProcessing);
                t.SaveToDatabase();

                var constr = (SqlConnectionStringBuilder)c.GetDistinctLiveDatabaseServer(DataAccessContext.InternalDataProcessing, false).Builder;
                Assert.AreEqual("myserver", constr.DataSource);
                Assert.False(constr.IntegratedSecurity);
                Assert.AreEqual("bob", constr.UserID);
                Assert.AreEqual("pass", constr.Password);
            }
            finally
            {
                t.DeleteInDatabase();
                if (cred != null)
                {
                    cred.DeleteInDatabase();
                }
                c.DeleteInDatabase();//no need to delete ci because of cascades
            }
        }
Example #3
0
        public void GetAllUsersOfACredential()
        {
            //Get all TableInfos that share this credential
            TableInfo tableInfo1 = new TableInfo(CatalogueRepository, "Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt1");
            TableInfo tableInfo2 = new TableInfo(CatalogueRepository, "Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt2");
            var       creds      = new DataAccessCredentials(CatalogueRepository, "bob");

            tableInfo1.SetCredentials(creds, DataAccessContext.InternalDataProcessing);
            tableInfo2.SetCredentials(creds, DataAccessContext.InternalDataProcessing);
            tableInfo1.SaveToDatabase();
            tableInfo2.SaveToDatabase();


            TableInfo[] TablesThatUseCredential = creds.GetAllTableInfosThatUseThis()[DataAccessContext.InternalDataProcessing].ToArray();

            Assert.AreEqual(TablesThatUseCredential[0], tableInfo1);
            Assert.AreEqual(TablesThatUseCredential[1], tableInfo2);

            tableInfo1.DeleteInDatabase();
            tableInfo2.DeleteInDatabase();
            creds.DeleteInDatabase();
        }
Example #4
0
        public void Create2TableInfosThatShareTheSameCredentialAndTestDeletingIt_ThrowsThatCredentialsHasDependencies()
        {
            //Get all TableInfos that share this credential
            TableInfo tableInfo1 = new TableInfo(CatalogueRepository, "Dependency1");
            TableInfo tableInfo2 = new TableInfo(CatalogueRepository, "Dependency2");
            var       creds      = new DataAccessCredentials(CatalogueRepository, "bob");

            try
            {
                tableInfo1.SetCredentials(creds, DataAccessContext.InternalDataProcessing);
                tableInfo2.SetCredentials(creds, DataAccessContext.InternalDataProcessing);
                tableInfo1.SaveToDatabase();
                tableInfo2.SaveToDatabase();

                var ex = Assert.Throws <CredentialsInUseException>(creds.DeleteInDatabase);//the bit that fails (because tables are there)
                Assert.AreEqual("Cannot delete credentials bob because it is in use by one or more TableInfo objects(Dependency1,Dependency2)", ex.Message);
            }
            finally
            {
                tableInfo1.DeleteInDatabase(); //will work
                tableInfo2.DeleteInDatabase(); //will work
                creds.DeleteInDatabase();      //will work
            }
        }
Example #5
0
        public void TestGettingConnectionStrings()
        {
            foreach (TableInfo tbl in CatalogueRepository.GetAllObjects <TableInfo>().Where(table => table.Name.ToLower().Equals("bob")))
            {
                tbl.DeleteInDatabase();
            }

            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(cred => cred.Name.ToLower().Equals("bob")))
            {
                c.DeleteInDatabase();
            }

            //test it with TableInfos
            TableInfo t = new TableInfo(CatalogueRepository, "Bob");

            try
            {
                t.Server   = "fish";
                t.Database = "bobsDatabase";
                t.SaveToDatabase();

                //t has no credentials
                var server = DataAccessPortal.GetInstance().ExpectServer(t, DataAccessContext.InternalDataProcessing);

                Assert.AreEqual(typeof(SqlConnectionStringBuilder), server.Builder.GetType());
                Assert.AreEqual("fish", ((SqlConnectionStringBuilder)server.Builder).DataSource);
                Assert.AreEqual("bobsDatabase", ((SqlConnectionStringBuilder)server.Builder).InitialCatalog);
                Assert.AreEqual(true, ((SqlConnectionStringBuilder)server.Builder).IntegratedSecurity);

                var creds = new DataAccessCredentials(CatalogueRepository, "Bob");
                try
                {
                    t.SetCredentials(creds, DataAccessContext.InternalDataProcessing, true);
                    creds.Username = "******";
                    creds.Password = "******";
                    creds.SaveToDatabase();

                    //credentials are cached
                    t.ClearAllInjections();

                    ////t has some credentials now
                    server = DataAccessPortal.GetInstance().ExpectServer(t, DataAccessContext.InternalDataProcessing);

                    Assert.AreEqual(typeof(SqlConnectionStringBuilder), server.Builder.GetType());
                    Assert.AreEqual("fish", ((SqlConnectionStringBuilder)server.Builder).DataSource);
                    Assert.AreEqual("bobsDatabase", ((SqlConnectionStringBuilder)server.Builder).InitialCatalog);
                    Assert.AreEqual("frank", ((SqlConnectionStringBuilder)server.Builder).UserID);
                    Assert.AreEqual("bobsPassword", ((SqlConnectionStringBuilder)server.Builder).Password);
                    Assert.AreEqual(false, ((SqlConnectionStringBuilder)server.Builder).IntegratedSecurity);
                }
                finally
                {
                    var linker = new TableInfoCredentialsManager(CatalogueRepository);
                    linker.BreakAllLinksBetween(creds, t);
                    creds.DeleteInDatabase();
                }
            }
            finally
            {
                t.DeleteInDatabase();
            }
        }