Merge pull request #270 from hashicorp/oss/merge-main-379f317d8b03e573cc2e35ccde06b040d8dc1862
[main] OSS to ENT merge of (379f317)
This commit is contained in:
commit
d8ea78c4b0
5 files changed
+269
-102
No files matched your search
@@ -24,4 +24,20 @@ export default class UserAbility extends ModelAbility {
|
||||
get canRemoveAccounts() {
|
||||
return this.hasAuthorizedAction('remove-accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
get canAddAccount() {
|
||||
const { account, canAddAccounts } = this;
|
||||
return canAddAccounts && !account.isUnknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
get canRemoveAccount() {
|
||||
const { account, canRemoveAccounts } = this;
|
||||
return canRemoveAccounts && !account.isUnknown;
|
||||
}
|
||||
}
|
||||
@@ -5,29 +5,147 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import {
|
||||
TYPE_AUTH_METHOD_LDAP,
|
||||
TYPE_AUTH_METHOD_OIDC,
|
||||
TYPE_AUTH_METHOD_PASSWORD,
|
||||
} from 'api/models/auth-method';
|
||||
|
||||
module('Unit | Abilities | User', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it reflects when a given user resource may add accounts based on authorized_actions', function (assert) {
|
||||
assert.expect(2);
|
||||
const service = this.owner.lookup('service:can');
|
||||
const model = {
|
||||
authorized_actions: ['add-accounts'],
|
||||
};
|
||||
assert.ok(service.can('addAccounts user', model));
|
||||
model.authorized_actions = [];
|
||||
assert.notOk(service.can('addAccounts user', model));
|
||||
let canService;
|
||||
let store;
|
||||
|
||||
const instances = {
|
||||
account: null,
|
||||
user: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
store = this.owner.lookup('service:store');
|
||||
instances.user = store.createRecord('user');
|
||||
instances.account = store.createRecord('account');
|
||||
});
|
||||
|
||||
test('it reflects when a given user resource may remove accounts based on authorized_actions', function (assert) {
|
||||
assert.expect(2);
|
||||
const service = this.owner.lookup('service:can');
|
||||
const model = {
|
||||
authorized_actions: ['remove-accounts'],
|
||||
};
|
||||
assert.ok(service.can('removeAccounts user', model));
|
||||
model.authorized_actions = [];
|
||||
assert.notOk(service.can('removeAccounts user', model));
|
||||
test('can add accounts to user when authorized and given a known account type', function (assert) {
|
||||
assert.expect(5);
|
||||
instances.user.authorized_actions = ['add-accounts'];
|
||||
assert.true(canService.can('addAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot add accounts to user when unauthorized', function (assert) {
|
||||
assert.expect(5);
|
||||
instances.user.authorized_actions = [];
|
||||
assert.false(canService.can('addAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('can remove accounts from user when authorized and given a known account type', function (assert) {
|
||||
assert.expect(5);
|
||||
instances.user.authorized_actions = ['remove-accounts'];
|
||||
assert.true(canService.can('removeAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot remove accounts from user when unauthorized', function (assert) {
|
||||
assert.expect(5);
|
||||
instances.user.authorized_actions = [];
|
||||
assert.false(canService.can('removeAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -3,10 +3,10 @@
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import AccountAbility from 'api/abilities/account';
|
||||
import UserAbility from 'api/abilities/user';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class OverrideAccountAbility extends AccountAbility {
|
||||
export default class OverrideUserAbility extends UserAbility {
|
||||
// =service
|
||||
@service features;
|
||||
|
||||
@@ -16,10 +16,14 @@ export default class OverrideAccountAbility extends AccountAbility {
|
||||
*/
|
||||
|
||||
get canAddAccount() {
|
||||
return this.features.isEnabled('ldap-auth-methods') || !this.model.isLDAP;
|
||||
return this.features.isEnabled('ldap-auth-methods') || !this.account.isLDAP
|
||||
? super.canAddAccount
|
||||
: false;
|
||||
}
|
||||
|
||||
get canRemoveAccount() {
|
||||
return this.features.isEnabled('ldap-auth-methods') || !this.model.isLDAP;
|
||||
return this.features.isEnabled('ldap-auth-methods') || !this.account.isLDAP
|
||||
? super.canRemoveAccount
|
||||
: false;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import {
|
||||
TYPE_AUTH_METHOD_LDAP,
|
||||
TYPE_AUTH_METHOD_OIDC,
|
||||
TYPE_AUTH_METHOD_PASSWORD,
|
||||
} from 'api/models/auth-method';
|
||||
|
||||
module('Unit | Abilities | account', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let store;
|
||||
let features;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
store = this.owner.lookup('service:store');
|
||||
features = this.owner.lookup('service:features');
|
||||
});
|
||||
|
||||
test('can add ldap account to user when feature flag enabled', function (assert) {
|
||||
assert.expect(1);
|
||||
features.enable('ldap-auth-methods');
|
||||
const account = store.createRecord('account', {
|
||||
type: TYPE_AUTH_METHOD_LDAP,
|
||||
});
|
||||
assert.true(canService.can('addAccount account', account));
|
||||
});
|
||||
|
||||
test('can add non-ldap account to user', function (assert) {
|
||||
assert.expect(2);
|
||||
const account = store.createRecord('account', {
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('addAccount account', account));
|
||||
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('addAccount account', account));
|
||||
});
|
||||
|
||||
test('cannot add ldap account to user when feature flag disabled', function (assert) {
|
||||
assert.expect(1);
|
||||
const account = store.createRecord('account', {
|
||||
type: TYPE_AUTH_METHOD_LDAP,
|
||||
});
|
||||
assert.false(canService.can('addAccount account', account));
|
||||
});
|
||||
|
||||
test('can remove ldap account from user when feature flag enabled', function (assert) {
|
||||
assert.expect(1);
|
||||
features.enable('ldap-auth-methods');
|
||||
const account = store.createRecord('account', {
|
||||
type: TYPE_AUTH_METHOD_LDAP,
|
||||
});
|
||||
assert.true(canService.can('removeAccount account', account));
|
||||
});
|
||||
|
||||
test('cannot remove ldap account from user when feature flag disabled', function (assert) {
|
||||
assert.expect(1);
|
||||
const account = store.createRecord('account', {
|
||||
type: TYPE_AUTH_METHOD_LDAP,
|
||||
});
|
||||
assert.false(canService.can('removeAccount account', account));
|
||||
});
|
||||
|
||||
test('can remove non-ldap account from user', function (assert) {
|
||||
assert.expect(2);
|
||||
const account = store.createRecord('account', {
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('removeAccount account', account));
|
||||
(account.type = TYPE_AUTH_METHOD_PASSWORD),
|
||||
assert.true(canService.can('removeAccount account', account));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import {
|
||||
TYPE_AUTH_METHOD_LDAP,
|
||||
TYPE_AUTH_METHOD_OIDC,
|
||||
TYPE_AUTH_METHOD_PASSWORD,
|
||||
} from 'api/models/auth-method';
|
||||
|
||||
module('Unit | Abilities | user', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let store;
|
||||
let features;
|
||||
|
||||
const instances = {
|
||||
account: null,
|
||||
user: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
store = this.owner.lookup('service:store');
|
||||
features = this.owner.lookup('service:features');
|
||||
instances.user = store.createRecord('user', {
|
||||
authorized_actions: ['add-accounts', 'remove-accounts'],
|
||||
});
|
||||
instances.account = store.createRecord('account');
|
||||
});
|
||||
|
||||
test('can add ldap account to user when feature flag enabled', function (assert) {
|
||||
assert.expect(1);
|
||||
features.enable('ldap-auth-methods');
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('can add non-ldap account to user', function (assert) {
|
||||
assert.expect(2);
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot add ldap account to user when feature flag disabled', function (assert) {
|
||||
assert.expect(1);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('can remove ldap account from user when feature flag enabled', function (assert) {
|
||||
assert.expect(1);
|
||||
features.enable('ldap-auth-methods');
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot remove ldap account from user when feature flag disabled', function (assert) {
|
||||
assert.expect(1);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('can remove non-ldap account from user', function (assert) {
|
||||
assert.expect(2);
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user