Beispiel #1
0
        public void generates_keys_of_specified_length()
        {
            KeysGeneratorProgram.Main(new[] { _keyFileName, _publicKeyFile, "2048" });
            var cryptoProvider = new RSACryptoServiceProvider();

            cryptoProvider.FromXmlString(File.ReadAllText(_keyFileName));
        }
Beispiel #2
0
 public virtual void SetUpFixture()
 {
     if (File.Exists(IssuerXmlPath))
     {
         File.Delete(IssuerXmlPath);
     }
     KeysGeneratorProgram.Main(new[] { IssuerXmlPath });
 }
Beispiel #3
0
 public void set_up()
 {
     _zipPackager = new ZipPackager();
     KeysGeneratorProgram.Main(new[]
     {
         IssuerXmlPath,
     });
 }
 public void fixture_set_up()
 {
     if (File.Exists(KeyFile))
     {
         File.Delete(KeyFile);
     }
     KeysGeneratorProgram.Main(new[] { KeyFile });
 }
Beispiel #5
0
        public void event_all_modules_loaded_is_catched_upon_every_success()
        {
            NomadKernel kernel = SetupMockedKernel();

            // subscribe kernel for event
            bool hasBeenLoaded = false;

            kernel.EventAggregator.Subscribe <NomadAllModulesLoadedMessage>((message) =>
            {
                Assert.AreNotEqual(0, message.ModuleInfos.Count());
                hasBeenLoaded = true;
            });

            //  compiling simple modules
            const string dir         = @"Modules\Kernel\SimpleAllModulesLoadedAwarenessTestModules\Simple\";
            const string fileName    = "AllModulesLoadedEventAwareModule.dll";
            const string module1Name = "SimpleModule1.dll";
            const string module2Name = "SimpleModule2.dll";
            const string keyFile     = @"newkey.xml";

            CompileSimpleModules(dir, keyFile, module1Name, module2Name);

            // compiling aware module
            var compiler = new ModuleCompiler
            {
                OutputDirectory =
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                 @"Modules\Kernel\SimpleAllModulesLoadedAwarenessTestModules\Aware\")
            };

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, fileName);

            string modulePath = compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\Kernel\AllModulesLoadedEventAwareModule.cs");

            KeysGeneratorProgram.Main(new[] { keyFile });
            compiler.GenerateManifestForModule(modulePath, keyFile);
            // set up module which subscribes for event

            // loading aware module
            IModuleDiscovery setUpDiscovery = SetUpDiscovery(new ModuleInfo(modulePath));

            Assert.DoesNotThrow(() => kernel.LoadModules(setUpDiscovery));

            // loading simple modules
            var directoryDiscovery = new DirectoryModuleDiscovery(dir, SearchOption.TopDirectoryOnly);

            Assert.DoesNotThrow(() => kernel.LoadModules(directoryDiscovery));

            //verify the method being called in a module.
            var carrier = (MessageCarrier)kernel.ModuleAppDomain.CreateInstanceAndUnwrap(
                typeof(MessageCarrier).Assembly.FullName, typeof(MessageCarrier).FullName);

            Assert.AreEqual(
                new[] { "AllModulesLoadedEventAwareModule", "AllModulesLoadedEventAwareModule" },
                carrier.List.ToArray());
            Assert.IsTrue(hasBeenLoaded);
        }
Beispiel #6
0
 public void generate_keys()
 {
     _keyFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                 @"Modules\signing-key.xml");
     _publicKeyFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                       @"Modules\public-key.xml");
     _issuerName = "test-issuer";
     KeysGeneratorProgram.Main(new[] { _keyFileName, _publicKeyFileName });
 }
Beispiel #7
0
 public void generates_non_empty_key_file()
 {
     KeysGeneratorProgram.Main(new[]
     {
         _keyFileName
     }
                               );
     File.Exists(_keyFileName);
 }
        public virtual void SetUpFixture()
        {
            if (File.Exists(KeyFile))
            {
                File.Delete(KeyFile);
            }
            KeysGeneratorProgram.Main(new[] { KeyFile });

            _moduleCompiler = new ModuleCompiler();
        }
Beispiel #9
0
 public void generates_public_key_file_if_asked()
 {
     KeysGeneratorProgram.Main(new[]
     {
         _keyFileName,
         _publicKeyFile
     }
                               );
     File.Exists(_keyFileName);
     File.Exists(_publicKeyFile);
 }
Beispiel #10
0
        public ModuleManifest GenerateManifest(string assemblyFilePath, string folderPath)
        {
            // build manifest with this settings
            KeysGeneratorProgram.Main(new[] { IssuerPath });

            var manifestBuilder = new ManifestBuilder(IssuerName, IssuerPath,
                                                      assemblyFilePath,
                                                      folderPath, KeyStorage.Nomad,
                                                      string.Empty, Configuration);

            return(manifestBuilder.Create());
        }
Beispiel #11
0
        exception_during_module_loading_is_changed_into_event_visible_from_module_and_kernel()
        {
            // set up configuration of kernel with mocks
            NomadKernel kernel = SetupMockedKernel();

            // set up listener for kernel side
            bool hasBeenCalled = false;

            kernel.EventAggregator.Subscribe <NomadAllModulesLoadedMessage>(
                (message) => hasBeenCalled = true);

            //  compile module for event aggregation
            const string dir      = @"Modules\Kernel\Event\";
            const string fileName = "EventAwareModule.dll";
            const string keyFile  = @"newkey.xml";

            var compiler = new ModuleCompiler
            {
                OutputDirectory =
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir)
            };

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, fileName);

            string modulePath = compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\Kernel\EventAwareModule.cs");

            KeysGeneratorProgram.Main(new[] { keyFile });
            compiler.GenerateManifestForModule(modulePath, keyFile);

            // set up module which subscribes for event
            IModuleDiscovery setUpDiscovery = SetUpDiscovery(new ModuleInfo(modulePath));

            kernel.LoadModules(setUpDiscovery);

            // set up the discovery mock
            IModuleDiscovery nonExistingDiscovery =
                SetUpDiscovery(new ModuleInfo("NonExistingModule.dll"));

            // perform test
            Assert.Throws <NomadCouldNotLoadModuleException>(
                () => kernel.LoadModules(nonExistingDiscovery),
                "Exception should  be thrown in kernel domain.");

            //verify the method being called in a module.
            var carrier = (MessageCarrier)kernel.ModuleAppDomain.CreateInstanceAndUnwrap(
                typeof(MessageCarrier).Assembly.FullName, typeof(MessageCarrier).FullName);

            Assert.AreEqual(new[] { "EventAwareModule" }, carrier.List.ToArray());
            Assert.IsTrue(hasBeenCalled);
        }
Beispiel #12
0
        private static void GenerateManifestUsingApi(string assemblyName, string path)
        {
            string keyFile = @"alaMaKota.xml";

            if (File.Exists(keyFile))
            {
                File.Delete(keyFile);
            }
            KeysGeneratorProgram.Main(new[] { keyFile });

            var builder = new Nomad.Utils.ManifestCreator.ManifestBuilder(@"TUTORIAL_ISSUER",
                                                                          keyFile,
                                                                          assemblyName,
                                                                          path);

            builder.CreateAndPublish();
        }
Beispiel #13
0
        private static void BuildModule()
        {
            // some remarkable constancies, we are using sample module from psake build
            const string issuerName    = @"TEST_ISSUER";
            const string issuerXmlPath = @"TEST_XML_KEY_FILE.xml";
            const string assemblyName  = @"Modules\Simple\SimplestModulePossible1.dll";

            // get the key file
            KeysGeneratorProgram.Main(new[] { Path.Combine(FolderPath, issuerXmlPath) });

            // get the assembly file into test folder
            File.Copy(assemblyName, Path.Combine(FolderPath, Path.GetFileName(assemblyName)), true);

            // NOTE: we are using here default builder configuration for simplicity of the test
            var manifestBuilder = new ManifestBuilder(issuerName,
                                                      Path.Combine(FolderPath, issuerXmlPath),
                                                      Path.GetFileName(assemblyName), FolderPath, KeyStorage.Nomad,
                                                      string.Empty, ManifestBuilderConfiguration.Default);

            manifestBuilder.CreateAndPublish();
        }
Beispiel #14
0
        /// <summary>
        ///		Generates the manifest for the file with coping all the dependencies and then removing them
        /// </summary>
        /// <remarks>
        ///		This method will be problematic with duplcate names and so on...
        /// </remarks>
        /// <param name="references">Path to all references</param>
        ///<returns>
        ///		The path to the generated manifest
        /// </returns>
        public string SetUpModuleWithManifest(string outputDirectory, string srcPath,
                                              ManifestBuilderConfiguration configuration,
                                              params string[] references)
        {
            OutputDirectory = outputDirectory;

            string modulePath = GenerateModuleFromCode(srcPath, references);

            // copy the references into folder with
            foreach (string reference in references)
            {
                File.Copy(reference, Path.Combine(outputDirectory, Path.GetFileName(reference)));
            }

            string KeyFile = @"alaMaKota.xml";

            if (File.Exists(KeyFile))
            {
                File.Delete(KeyFile);
            }
            KeysGeneratorProgram.Main(new[] { KeyFile });

            // manifest generating is for folder
            string file = GenerateManifestForModule(modulePath, KeyFile, configuration);

            if (File.Exists(KeyFile))
            {
                File.Delete(KeyFile);
            }

            // remove those references
            foreach (string reference in references)
            {
                File.Delete(Path.Combine(outputDirectory, Path.GetFileName(reference)));
            }

            return(file);
        }
Beispiel #15
0
        private static void CompileSimpleModules(string dir, string keyFile,
                                                 string simpleModule1Name, string simpleModule2Name)
        {
            var compiler = new ModuleCompiler
            {
                OutputDirectory =
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir)
            };

            KeysGeneratorProgram.Main(new[] { keyFile });

            // generating not subcribed modules
            compiler.OutputName = Path.Combine(compiler.OutputDirectory, simpleModule1Name);
            string module1Path =
                compiler.GenerateModuleFromCode(ModuleCompiler.DefaultSimpleModuleSource);

            compiler.GenerateManifestForModule(module1Path, keyFile);

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, simpleModule2Name);
            string module2Path =
                compiler.GenerateModuleFromCode(ModuleCompiler.DefaultSimpleModuleSourceAlternative);

            compiler.GenerateManifestForModule(module2Path, keyFile);
        }