-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
1,016 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright (c) The University of Dundee 2018-2019 | ||
// This file is part of the Research Data Management Platform (RDMP). | ||
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
// RDMP 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 RDMP. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using Rdmp.Core.CommandLine.Options; | ||
using Rdmp.Core.CommandLine.Runners; | ||
using Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.DataFlowPipeline; | ||
using ReusableLibraryCode.Checks; | ||
using ReusableLibraryCode.Progress; | ||
using Tests.Common; | ||
|
||
namespace Rdmp.Core.Tests.CommandLine | ||
{ | ||
class RdmpScriptTests : UnitTests | ||
{ | ||
[TestCase("NewObject Catalogue 'trog dor'","trog dor")] | ||
[TestCase("NewObject Catalogue \"trog dor\"","trog dor")] | ||
[TestCase("NewObject Catalogue \"'trog dor'\"","'trog dor'")] | ||
[TestCase("NewObject Catalogue '\"trog dor\"'","\"trog dor\"")] | ||
|
||
public void RdmpScript_NewObject_Catalogue(string command, string expectedName) | ||
{ | ||
foreach(var c in RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>()) | ||
c.DeleteInDatabase(); | ||
|
||
var runner = new ExecuteCommandRunner(new ExecuteCommandOptions() | ||
{ | ||
Script = new RdmpScript() | ||
{ | ||
Commands = new[] {command} | ||
} | ||
}); | ||
|
||
SetupMEF(); | ||
|
||
var exitCode = runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); | ||
|
||
Assert.AreEqual(0,exitCode); | ||
Assert.AreEqual(1,RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>().Length); | ||
|
||
Assert.AreEqual(expectedName,RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>().Single().Name); | ||
} | ||
|
||
[TestCase("NewObject Catalogue 'fffff'","NewObject CatalogueItem Catalogue:*fff* 'bbbb'","bbbb")] | ||
[TestCase("NewObject Catalogue '\"fff\"'","NewObject CatalogueItem 'Catalogue:\"fff\"' 'bbbb'","bbbb")] | ||
[TestCase("NewObject Catalogue '\"ff ff\"'","NewObject CatalogueItem 'Catalogue:\"ff ff\"' 'bb bb'","bb bb")] | ||
[TestCase("NewObject Catalogue '\"ff ff\"'","NewObject CatalogueItem 'Catalogue:\"ff ff\"' bb'bb","bb'bb")] | ||
[TestCase("NewObject Catalogue '\"ff ff\"'","NewObject CatalogueItem 'Catalogue:\"ff ff\"' b\"b'bb'","b\"b'bb'")] | ||
public void RdmpScript_NewObject_CatalogueItem(string cataCommand,string cataItemCommand, string expectedCataItemName) | ||
{ | ||
foreach(var c in RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>()) | ||
c.DeleteInDatabase(); | ||
|
||
var runner = new ExecuteCommandRunner(new ExecuteCommandOptions() | ||
{ | ||
Script = new RdmpScript() | ||
{ | ||
Commands = new[] | ||
{ | ||
cataCommand, | ||
cataItemCommand | ||
} | ||
} | ||
}); | ||
|
||
SetupMEF(); | ||
|
||
var exitCode = runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new ThrowImmediatelyCheckNotifier(), new GracefulCancellationToken()); | ||
|
||
Assert.AreEqual(0,exitCode); | ||
Assert.AreEqual(1,RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>().Length); | ||
var ci = RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>().Single().CatalogueItems.Single(); | ||
|
||
Assert.AreEqual(expectedCataItemName,ci.Name); | ||
|
||
} | ||
|
||
[Test] | ||
public void Test_SplitCommandLine() | ||
{ | ||
var vals = ExecuteCommandRunner.SplitCommandLine("NewObject CatalogueItem 'Catalogue:\"fff\"' 'bbbb'").ToArray(); | ||
Assert.AreEqual("NewObject",vals[0]); | ||
Assert.AreEqual("CatalogueItem",vals[1]); | ||
Assert.AreEqual("Catalogue:\"fff\"",vals[2]); | ||
Assert.AreEqual("bbbb",vals[3]); | ||
} | ||
[Test] | ||
public void Test_SplitCommandLine_QuotesInStrings() | ||
{ | ||
var vals = ExecuteCommandRunner.SplitCommandLine("NewObject CatalogueItem bb\"'bb'").ToArray(); | ||
Assert.AreEqual("NewObject",vals[0]); | ||
Assert.AreEqual("CatalogueItem",vals[1]); | ||
Assert.AreEqual("bb\"'bb'",vals[2]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) The University of Dundee 2018-2019 | ||
// This file is part of the Research Data Management Platform (RDMP). | ||
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
// RDMP 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 RDMP. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using NUnit.Framework; | ||
using Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.Curation.Data.Aggregation; | ||
using Rdmp.Core.Curation.Data.Cohort; | ||
using Rdmp.Core.Curation.Data.Spontaneous; | ||
using Rdmp.Core.DataExport.Data; | ||
using Rdmp.Core.Repositories; | ||
using Tests.Common; | ||
|
||
namespace Rdmp.Core.Tests.Curation.Unit | ||
{ | ||
class IMightBeReadOnlyTests : UnitTests | ||
{ | ||
[Test] | ||
public void IsReadonly_AggregateFilterContainer() | ||
{ | ||
//im probably an orphan | ||
var c = WhenIHaveA<AggregateFilterContainer>(); | ||
Assert.IsFalse(c.ShouldBeReadOnly(out _)); | ||
|
||
//now I am in a cic | ||
var cic = WhenIHaveA<CohortIdentificationConfiguration>(); | ||
cic.Name = "fff"; | ||
cic.CreateRootContainerIfNotExists(); | ||
cic.RootCohortAggregateContainer.AddChild(c.GetAggregate(),0); | ||
|
||
Assert.IsFalse(c.ShouldBeReadOnly(out _)); | ||
|
||
cic.Frozen = true; | ||
Assert.IsTrue(c.ShouldBeReadOnly(out string reason)); | ||
|
||
Assert.AreEqual("fff is Frozen",reason); | ||
} | ||
|
||
[Test] | ||
public void IsReadonly_ExtractionFilterContainer() | ||
{ | ||
var c = WhenIHaveA<FilterContainer>(); | ||
Assert.IsFalse(c.ShouldBeReadOnly(out _)); | ||
|
||
var ec = c.GetSelectedDataSetIfAny().ExtractionConfiguration; | ||
|
||
Assert.IsFalse(c.ShouldBeReadOnly(out _)); | ||
|
||
ec.Name = "lll"; | ||
ec.IsReleased = true; | ||
Assert.IsTrue(c.ShouldBeReadOnly(out string reason)); | ||
|
||
Assert.AreEqual("lll has already been released",reason); | ||
} | ||
|
||
[Test] | ||
public void IsReadonly_SpontaneousContainer() | ||
{ | ||
var memoryrepo = new MemoryCatalogueRepository(); | ||
var c = new SpontaneouslyInventedFilterContainer(memoryrepo,null,null,FilterContainerOperation.AND); | ||
Assert.IsFalse(c.ShouldBeReadOnly(out _),"Spont containers should never be in UI but lets not tell the programmer they shouldn't be edited"); | ||
} | ||
|
||
|
||
|
||
[Test] | ||
public void IsReadonly_AggregateFilter() | ||
{ | ||
//im probably an orphan | ||
var f = WhenIHaveA<AggregateFilter>(); | ||
Assert.IsFalse(f.ShouldBeReadOnly(out _)); | ||
|
||
//now I am in a cic | ||
var cic = WhenIHaveA<CohortIdentificationConfiguration>(); | ||
cic.Name = "fff"; | ||
cic.CreateRootContainerIfNotExists(); | ||
cic.RootCohortAggregateContainer.AddChild(f.GetAggregate(),0); | ||
|
||
Assert.IsFalse(f.ShouldBeReadOnly(out _)); | ||
|
||
cic.Frozen = true; | ||
Assert.IsTrue(f.ShouldBeReadOnly(out string reason)); | ||
|
||
Assert.AreEqual("fff is Frozen",reason); | ||
} | ||
|
||
[Test] | ||
public void IsReadonly_DeployedExtractionFilter() | ||
{ | ||
var f = WhenIHaveA<DeployedExtractionFilter>(); | ||
Assert.IsFalse(f.ShouldBeReadOnly(out _)); | ||
|
||
var ec = ((FilterContainer) f.FilterContainer).GetSelectedDataSetIfAny().ExtractionConfiguration; | ||
ec.Name = "lll"; | ||
ec.IsReleased = true; | ||
Assert.IsTrue(f.ShouldBeReadOnly(out string reason)); | ||
|
||
Assert.AreEqual("lll has already been released",reason); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCreatePrivateKey.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) The University of Dundee 2018-2019 | ||
// This file is part of the Research Data Management Platform (RDMP). | ||
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
// RDMP 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 RDMP. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using System.IO; | ||
using Rdmp.Core.Repositories.Managers; | ||
|
||
namespace Rdmp.Core.CommandExecution.AtomicCommands | ||
{ | ||
/// <summary> | ||
/// Creates a new private key for encrypting credentials in RDMP. Old passwords will not decrypt using the new key and will be lost (unless you have the original key) | ||
/// </summary> | ||
public class ExecuteCommandCreatePrivateKey : BasicCommandExecution | ||
{ | ||
private readonly FileInfo _keyFileToCreate; | ||
private PasswordEncryptionKeyLocation _encryption; | ||
|
||
public ExecuteCommandCreatePrivateKey(IBasicActivateItems activator, FileInfo keyFileToCreate) : base(activator) | ||
{ | ||
_keyFileToCreate = keyFileToCreate; | ||
_encryption = activator.RepositoryLocator.CatalogueRepository.EncryptionManager as PasswordEncryptionKeyLocation; | ||
|
||
if (_encryption == null) | ||
{ | ||
SetImpossible("Current Encryption manager is not based on key files"); | ||
return; | ||
} | ||
|
||
var existing = _encryption.GetKeyFileLocation(); | ||
if (existing != null) | ||
SetImpossible($"There is already a key file at '{existing}'"); | ||
} | ||
|
||
public override void Execute() | ||
{ | ||
base.Execute(); | ||
|
||
_encryption.CreateNewKeyFile(_keyFileToCreate.FullName); | ||
} | ||
} | ||
} |
Oops, something went wrong.