public void CanAuthorizeAuthenticateAnonymousUser()
        {
            AzureStorage storage = new AzureStorage();

            OverlordIdentity.InitializeUserIdentity(TestData.user_01_id.UrnToId(), "admin", new string[0]);
            Assert.Throws(typeof(System.Security.SecurityException),
                          () => storage.AuthenticateAnonymousUser(TestData.user_01_id, "admin"));
        }
        public void CanAuthorizeAddUser()
        {
            OverlordIdentity.InitializeUserIdentity(TestData.user_01_id.UrnToId(), "admin", new string[0]);
            AzureStorage storage = new AzureStorage();

            Assert.Throws(typeof(System.Security.SecurityException), () =>
                          storage.AddUser("XUnit_CanAuthorizeAddAzureStorageTests.user_Test_Name", "XUnit_CanAuthorizeAddAzureStorageTests.user_Test_Token",
                                          null));
        }
        public void CanAuthorizeDeleteUser()
        {
            OverlordIdentity.InitializeUserIdentity(TestData.user_01_id.UrnToId(), "admin", new string[0]);
            AzureStorage storage = new AzureStorage();

            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            IStorageUser user = storage.FindUser("d155074f-4e85-4cb5-a597-8bfecb0dfc04".ToGuid(), "admin");

            Assert.Throws(typeof(System.Security.SecurityException), () => storage.DeleteUser(user));
            OverlordIdentity.InitializeAdminUserIdentity(TestData.user_01_id.UrnToId(), "admin", new string[0]);
            Assert.Throws(typeof(System.Security.SecurityException), () => storage.DeleteUser(user));
        }
Пример #4
0
 public void CanInitializeIdentity()
 {
     Assert.False(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Anonymous));
     OverlordIdentity.InitializeAnonymousIdentity();
     Assert.True(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Anonymous));
     OverlordIdentity.InitializeDeviceIdentity(TestData.device_01_id.UrnToId(), TestData.device_01_token, new string[0]);
     Assert.False(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Anonymous));
     Assert.True(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Device));
     OverlordIdentity.InitializeUserIdentity(TestData.user_01_id.UrnToId(), TestData.user_01_token, new string[0]);
     Assert.False(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Device));
     Assert.True(OverlordIdentity.HasClaim(Authentication.Role, UserRole.User));
 }
Пример #5
0
        public void CanFindDevice()
        {
            //InitialiseTestData();
            AzureStorage storage = new AzureStorage();

            OverlordIdentity.InitializeUserIdentity(TestData.user_02_id, TestData.user_02_token, new string[0]);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            IStorageUser user = storage.FindUser(TestData.user_01_id.UrnToGuid(), TestData.user_01_token);

            Assert.NotNull(user);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindDevice);
            IStorageDevice device = storage.FindDevice(TestData.device_01_id.UrnToGuid(), TestData.device_01_token);

            Assert.NotNull(device);
        }
Пример #6
0
        public bool AuthenticateAnonymousUser(string user_id, string user_token)
        {
            TableOperation retrieveOperation = TableOperation.Retrieve <DynamicTableEntity>(user_id,
                                                                                            user_token);

            try
            {
                DynamicTableEntity user_entity = (DynamicTableEntity)this.UsersTable.Execute
                                                     (retrieveOperation).Result;
                if (user_entity == null)
                {
                    return(false);
                }
                else
                {
                    IStorageUser user = this.UserEntityResolver(user_entity.PartitionKey,
                                                                user_entity.RowKey, user_entity.Timestamp, user_entity.Properties, user_entity.ETag);
                    OverlordIdentity.InitializeUserIdentity(user.Id.ToUrn(), user.Token,
                                                            user.Devices.Select(d => d.ToUrn()).ToList <String>());
                    return(true);
                }
            }
            catch (Exception e)
            {
                Log.ReadTableFailure(string.Format("Failed to read user entity: Id: {0}, Token: {1}.",
                                                   user_id, user_token), e);
                throw;
            }
            finally
            {
            }


            /*
             * TableOperation retrieveOperation = TableOperation.Retrieve<DynamicTableEntity>(urn_id, token);
             * TableQuery<DynamicTableEntity> query = new TableQuery<DynamicTableEntity>().Where(
             *  TableQuery.CombineFilters(
             *      TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, urn_id.UrnToId()),
             *      TableOperators.And,
             *      TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, token)
             *  )
             * );
             * IEnumerable<IStorageUser> user = this.UsersTable.ExecuteQuery<DynamicTableEntity, IStorageUser>(query, this.UserEntityResolverFunc);
             * return user.FirstOrDefault();
             */
            //return null;
        }
Пример #7
0
        public void CanAddDevice()
        {
            AzureStorage storage = new AzureStorage();

            OverlordIdentity.InitializeUserIdentity(TestData.user_02_id,
                                                    TestData.user_02_token, new string[0]);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            IStorageUser user = storage.FindUser(TestData.user_02_id.UrnToGuid(),
                                                 TestData.user_02_token);

            Assert.NotNull(user);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice);
            IStorageDevice device = storage.AddDevice(user, "xUnit_CanAddDeviceTest_Name",
                                                      "xUnit_CanAddDeviceTest_Token", null);

            Assert.NotNull(device.Id);
            Assert.Equal("xUnit_CanAddDeviceTest_Name", device.Name);
            Assert.Equal("xUnit_CanAddDeviceTest_Token", device.Token);
            Assert.True(user.Devices.Contains(device.Id));
        }
Пример #8
0
        private void InitialiseTestData()
        {
            AzureStorage storage = new AzureStorage();

            OverlordIdentity.InitializeUserIdentity(TestData.user_02_id, TestData.user_02_token, new string[0]);

            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            IStorageUser user = storage.FindUser(TestData.user_02_id.UrnToGuid(), TestData.user_02_token);

            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice);
            IStorageDevice device_01 = storage.AddDevice(user, TestData.device_01_name, TestData.device_01_token, null, TestData.device_01_id);

            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            //user = storage.FindUser(AzureStorageTests.user_02_id.UrnToGuid(), AzureStorageTests.user_02_token);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice);
            IStorageDevice device_02 = storage.AddDevice(user, TestData.device_02_name, TestData.device_02_token, null, TestData.device_02_id);

            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            //user = storage.FindUser(AzureStorageTests.user_02_id.UrnToGuid(), AzureStorageTests.user_02_token);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice);
            IStorageDevice device_03 = storage.AddDevice(user, TestData.device_03_name, TestData.device_03_token, null, TestData.device_03_id);
        }