Ejemplo n.º 1
0
        public void Test_fromJson()
        {
            // Loads the JSON string.
            SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/dockerconfig.json").ToURI());

            // Deserializes into a docker config JSON object.
            DockerConfig dockerConfig =
                new DockerConfig(JsonTemplateMapper.ReadJsonFromFile <DockerConfigTemplate>(jsonFile));

            Assert.AreEqual("some:auth", DecodeBase64(dockerConfig.GetAuthFor("some registry")));
            Assert.AreEqual(
                "some:other:auth", DecodeBase64(dockerConfig.GetAuthFor("some other registry")));
            Assert.AreEqual("token", DecodeBase64(dockerConfig.GetAuthFor("registry")));
            Assert.AreEqual("token", DecodeBase64(dockerConfig.GetAuthFor("https://registry")));
            Assert.IsNull(dockerConfig.GetAuthFor("just registry"));

            Assert.AreEqual(
                Paths.Get("docker-credential-some credential store"),
                dockerConfig.GetCredentialHelperFor("some registry").GetCredentialHelper());
            Assert.AreEqual(
                Paths.Get("docker-credential-some credential store"),
                dockerConfig.GetCredentialHelperFor("some other registry").GetCredentialHelper());
            Assert.AreEqual(
                Paths.Get("docker-credential-some credential store"),
                dockerConfig.GetCredentialHelperFor("just registry").GetCredentialHelper());
            Assert.AreEqual(
                Paths.Get("docker-credential-some credential store"),
                dockerConfig.GetCredentialHelperFor("with.protocol").GetCredentialHelper());
            Assert.AreEqual(
                Paths.Get("docker-credential-another credential helper"),
                dockerConfig.GetCredentialHelperFor("another registry").GetCredentialHelper());
            Assert.IsNull(dockerConfig.GetCredentialHelperFor("unknonwn registry"));
        }
Ejemplo n.º 2
0
        public void TestGetAuthFor_orderOfMatchPreference()
        {
            SystemPath json =
                Paths.Get(TestResources.GetResource("core/json/dockerconfig_extra_matches.json").ToURI());

            DockerConfig dockerConfig =
                new DockerConfig(JsonTemplateMapper.ReadJsonFromFile <DockerConfigTemplate>(json));

            Assert.AreEqual("my-registry: exact match", dockerConfig.GetAuthFor("my-registry"));
            Assert.AreEqual("cool-registry: with https", dockerConfig.GetAuthFor("cool-registry"));
            Assert.AreEqual(
                "awesome-registry: starting with name", dockerConfig.GetAuthFor("awesome-registry"));
            Assert.AreEqual(
                "dull-registry: starting with name and with https",
                dockerConfig.GetAuthFor("dull-registry"));
        }
Ejemplo n.º 3
0
        public void TestGetAuthFor_correctSuffixMatching()
        {
            SystemPath json =
                Paths.Get(TestResources.GetResource("core/json/dockerconfig_extra_matches.json").ToURI());

            DockerConfig dockerConfig =
                new DockerConfig(JsonTemplateMapper.ReadJsonFromFile <DockerConfigTemplate>(json));

            Assert.IsNull(dockerConfig.GetAuthFor("example"));
        }