Ejemplo n.º 1
0
        public Fakes()
        {
            _users = Get <User>();
            _packageRegistrations = Get <PackageRegistration>();

            var key = 39;
            var credentialBuilder = new CredentialBuilder();

            ApiKeyV3PlaintextValue = "889e180e-335c-491a-ac26-e83c4bd31d87";

            User = new User("testUser")
            {
                Key          = key++,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential>
                {
                    credentialBuilder.CreatePasswordCredential(Password),
                    TestCredentialHelper.CreateV1ApiKey(Guid.Parse("669e180e-335c-491a-ac26-e83c4bd31d65"),
                                                        ExpirationForApiKeyV1),
                    TestCredentialHelper.CreateV2ApiKey(Guid.Parse("779e180e-335c-491a-ac26-e83c4bd31d87"),
                                                        ExpirationForApiKeyV1).WithDefaultScopes(),
                    TestCredentialHelper.CreateV3ApiKey(Guid.Parse(ApiKeyV3PlaintextValue),
                                                        ExpirationForApiKeyV1).WithDefaultScopes(),
                    TestCredentialHelper.CreateV4ApiKey(null, out string apiKeyV4PlaintextValue).WithDefaultScopes(),
                    TestCredentialHelper.CreateV2VerificationApiKey(Guid.Parse("b0c51551-823f-4701-8496-43980b4b3913")),
                    TestCredentialHelper.CreateExternalCredential("abc")
                },
Ejemplo n.º 2
0
        public void FiltersOutUnsupportedCredentials()
        {
            // Arrange
            var credentialBuilder = new CredentialBuilder();
            var credentials       = new List <Credential> {
                credentialBuilder.CreatePasswordCredential("v3"),
                TestCredentialHelper.CreatePbkdf2Password("pbkdf2"),
                TestCredentialHelper.CreateSha1Password("sha1"),
                TestCredentialHelper.CreateV1ApiKey(Guid.NewGuid(), Fakes.ExpirationForApiKeyV1),
                TestCredentialHelper.CreateV2ApiKey(Guid.NewGuid(), Fakes.ExpirationForApiKeyV1),
                TestCredentialHelper.CreateV2VerificationApiKey(Guid.NewGuid()),
                credentialBuilder.CreateExternalCredential("MicrosoftAccount", "blarg", "Bloog"),
                new Credential {
                    Type = "unsupported"
                }
            };

            var user = new User
            {
                Username    = "******",
                Credentials = credentials
            };

            // Act
            var userAuditRecord = new UserAuditRecord(user, AuditedUserAction.AddCredential);

            // Assert
            var auditRecords = userAuditRecord.Credentials.ToDictionary(c => c.Type);

            Assert.Equal(7, auditRecords.Count);
            Assert.True(auditRecords.ContainsKey(credentials[0].Type));
            Assert.True(auditRecords.ContainsKey(credentials[1].Type));
            Assert.True(auditRecords.ContainsKey(credentials[2].Type));
            Assert.True(auditRecords.ContainsKey(credentials[3].Type));
            Assert.True(auditRecords.ContainsKey(credentials[4].Type));
            Assert.True(auditRecords.ContainsKey(credentials[5].Type));
            Assert.True(auditRecords.ContainsKey(credentials[6].Type));
        }
Ejemplo n.º 3
0
        public Fakes()
        {
            User = new User("testUser")
            {
                Key          = 40,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential>
                {
                    new CredentialBuilder().CreatePasswordCredential(Password),
                    TestCredentialHelper.CreateV1ApiKey(Guid.Parse("669e180e-335c-491a-ac26-e83c4bd31d65"),
                                                        ExpirationForApiKeyV1),
                    TestCredentialHelper.CreateV2ApiKey(Guid.Parse("779e180e-335c-491a-ac26-e83c4bd31d87"),
                                                        ExpirationForApiKeyV1),
                    TestCredentialHelper.CreateV2VerificationApiKey(Guid.Parse("b0c51551-823f-4701-8496-43980b4b3913")),
                    TestCredentialHelper.CreateExternalCredential("abc")
                }
            };

            Pbkdf2User = new User("testPbkdf2User")
            {
                Key          = 41,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential>
                {
                    TestCredentialHelper.CreatePbkdf2Password(Password),
                    TestCredentialHelper.CreateV1ApiKey(Guid.Parse("519e180e-335c-491a-ac26-e83c4bd31d65"),
                                                        ExpirationForApiKeyV1)
                }
            };

            ShaUser = new User("testShaUser")
            {
                Key          = 42,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential>
                {
                    TestCredentialHelper.CreateSha1Password(Password),
                    TestCredentialHelper.CreateV1ApiKey(Guid.Parse("b9704a41-4107-4cd2-bcfa-70d84e021ab2"),
                                                        ExpirationForApiKeyV1)
                }
            };

            Admin = new User("testAdmin")
            {
                Key          = 43,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential> {
                    TestCredentialHelper.CreatePbkdf2Password(Password)
                },
                Roles = new List <Role> {
                    new Role {
                        Name = Constants.AdminRoleName
                    }
                }
            };

            Owner = new User("testPackageOwner")
            {
                Key         = 44,
                Credentials = new List <Credential> {
                    TestCredentialHelper.CreatePbkdf2Password(Password)
                },
                EmailAddress = "*****@*****.**" //package owners need confirmed email addresses, obviously.
            };

            Package = new PackageRegistration
            {
                Id     = "FakePackage",
                Owners = new List <User> {
                    Owner
                },
                Packages = new List <Package>
                {
                    new Package {
                        Version = "1.0"
                    },
                    new Package {
                        Version = "2.0"
                    }
                }
            };
        }
Ejemplo n.º 4
0
        public Fakes()
        {
            _users = Get <User>();
            _packageRegistrations = Get <PackageRegistration>();

            var key = 39;
            var credentialBuilder = new CredentialBuilder();

            User = new User("testUser")
            {
                Key          = key++,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential>
                {
                    credentialBuilder.CreatePasswordCredential(Password),
                    TestCredentialHelper.CreateV1ApiKey(Guid.Parse("669e180e-335c-491a-ac26-e83c4bd31d65"),
                                                        ExpirationForApiKeyV1),
                    TestCredentialHelper.CreateV2ApiKey(Guid.Parse("779e180e-335c-491a-ac26-e83c4bd31d87"),
                                                        ExpirationForApiKeyV1).WithDefaultScopes(),
                    TestCredentialHelper.CreateV4ApiKey(null, out string apiKeyV4PlaintextValue).WithDefaultScopes(),
                    TestCredentialHelper.CreateV2VerificationApiKey(Guid.Parse("b0c51551-823f-4701-8496-43980b4b3913")),
                    TestCredentialHelper.CreateExternalCredential("abc")
                }
            };

            ApiKeyV4PlaintextValue = apiKeyV4PlaintextValue;

            Organization = new Organization("testOrganization")
            {
                Key          = key++,
                EmailAddress = "*****@*****.**",
                // invalid credentials for testing authentication constraints
                Credentials = new List <Credential>
                {
                    credentialBuilder.CreatePasswordCredential(Password)
                }
            };

            CreateOrganizationUsers(ref key, credentialBuilder, "", out var organization, out var organizationAdmin, out var organizationCollaborator);
            Organization             = organization;
            OrganizationAdmin        = organizationAdmin;
            OrganizationCollaborator = organizationCollaborator;

            CreateOrganizationUsers(ref key, credentialBuilder, "Owner", out var organizationOwner, out var organizationAdminOwner, out var organizationCollaboratorOwner);
            OrganizationOwner             = organizationOwner;
            OrganizationOwnerAdmin        = organizationAdminOwner;
            OrganizationOwnerCollaborator = organizationCollaboratorOwner;

            Pbkdf2User = new User("testPbkdf2User")
            {
                Key          = key++,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential>
                {
                    TestCredentialHelper.CreatePbkdf2Password(Password),
                    TestCredentialHelper.CreateV1ApiKey(Guid.Parse("519e180e-335c-491a-ac26-e83c4bd31d65"),
                                                        ExpirationForApiKeyV1)
                }
            };

            ShaUser = new User("testShaUser")
            {
                Key          = key++,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential>
                {
                    TestCredentialHelper.CreateSha1Password(Password),
                    TestCredentialHelper.CreateV1ApiKey(Guid.Parse("b9704a41-4107-4cd2-bcfa-70d84e021ab2"),
                                                        ExpirationForApiKeyV1)
                }
            };

            Admin = new User("testAdmin")
            {
                Key          = key++,
                EmailAddress = "*****@*****.**",
                Credentials  = new List <Credential> {
                    TestCredentialHelper.CreatePbkdf2Password(Password)
                },
                Roles = new List <Role> {
                    new Role {
                        Name = Constants.AdminRoleName
                    }
                }
            };

            Owner = new User("testPackageOwner")
            {
                Key         = key++,
                Credentials = new List <Credential> {
                    TestCredentialHelper.CreatePbkdf2Password(Password)
                },
                EmailAddress = "*****@*****.**" //package owners need confirmed email addresses, obviously.
            };

            Package = new PackageRegistration
            {
                Id     = "FakePackage",
                Owners = new List <User> {
                    Owner, OrganizationOwner
                },
            };
            Package.Packages = new List <Package>
            {
                new Package {
                    Version = "1.0", PackageRegistration = Package
                },
                new Package {
                    Version = "2.0", PackageRegistration = Package
                }
            };
        }