diff --git a/package.json b/package.json index 42801c648..bc536ae12 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "lint:fix": "eslint --ext .js,.vue src tests --fix", "stylelint": "stylelint css src", "stylelint:fix": "stylelint css src --fix", - "test:unit": "jest --silent", + "test:unit": "jest", "test:unit:watch": "jest --watch --no-coverage" }, "repository": { diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 5c24ab197..02b012a25 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -858,7 +858,7 @@ export default { if (this.state.openproject_instance_url && this.state.openproject_client_id && this.state.openproject_client_secret && this.state.nc_oauth_client) { this.showDefaultManagedProjectFolders = true } - if (this.state.openproject_instance_url && this.state.authorization_settings.oidc_provider && this.state.authorization_settings.targeted_audience_client_id) { + if (this.state.authorization_method === AUTH_METHOD.OIDC && this.state.openproject_instance_url && this.state.authorization_settings.oidc_provider && this.state.authorization_settings.targeted_audience_client_id) { this.showDefaultManagedProjectFolders = true } if (this.state.fresh_project_folder_setup === false) { @@ -873,7 +873,7 @@ export default { this.isFormCompleted.authorizationMethod = true this.authorizationMethod.authorizationMethodSet = this.authorizationMethod.currentAuthorizationMethodSelected = this.state.authorization_method } - if (this.state.authorization_settings.oidc_provider !== '' && this.state.authorization_settings.targeted_audience_client_id !== '') { + if (this.state.authorization_method === AUTH_METHOD.OIDC && this.state.authorization_settings.oidc_provider !== '' && this.state.authorization_settings.targeted_audience_client_id !== '') { this.formMode.authorizationSetting = F_MODES.VIEW this.isFormCompleted.authorizationSetting = true this.authorizationSetting.oidcProviderSet = this.authorizationSetting.currentOIDCProviderSelected = this.state.authorization_settings.oidc_provider @@ -889,11 +889,20 @@ export default { } } if (this.state.openproject_instance_url && this.state.authorization_method) { - if (!this.state.openproject_client_id || !this.state.openproject_client_secret) { + if (!this.state.openproject_client_id && !this.state.openproject_client_secret) { this.formMode.opOauth = F_MODES.EDIT } - if (!this.state.authorization_settings.oidc_provider || !this.state.authorization_settings.targeted_audience_client_id) { - this.formMode.authorizationSetting = F_MODES.EDIT + } + if (this.state.openproject_instance_url && this.state.authorization_method) { + if (this.state.authorization_method === AUTH_METHOD.OAUTH2) { + if (!this.state.openproject_client_id || !this.state.openproject_client_secret) { + this.formMode.authorizationSetting = F_MODES.EDIT + } + } + if (this.state.authorization_method === AUTH_METHOD.OIDC) { + if (!this.state.authorization_settings.oidc_provider || !this.state.authorization_settings.targeted_audience_client_id) { + this.formMode.authorizationSetting = F_MODES.EDIT + } } } if (this.state.nc_oauth_client) { @@ -1193,9 +1202,9 @@ export default { this.state.openproject_client_secret = null this.state.default_enable_navigation = false this.state.openproject_instance_url = null - this.authorizationMethod.authorizationMethodSet = null - this.authorizationSetting.currentOIDCProviderSelected = null this.state.authorization_settings.targeted_audience_client_id = null + this.authorizationSetting.currentOIDCProviderSelected = null + this.authorizationMethod.authorizationMethodSet = null this.state.default_enable_unified_search = false this.oPUserAppPassword = null await this.saveOPOptions() diff --git a/tests/jest/components/AdminSettings.spec.js b/tests/jest/components/AdminSettings.spec.js index 1f5dac62c..50cab6d69 100644 --- a/tests/jest/components/AdminSettings.spec.js +++ b/tests/jest/components/AdminSettings.spec.js @@ -3,7 +3,7 @@ import axios from '@nextcloud/axios' import { createLocalVue, shallowMount, mount } from '@vue/test-utils' import AdminSettings from '../../../src/components/AdminSettings.vue' -import { F_MODES } from '../../../src/utils.js' +import { F_MODES, AUTH_METHOD } from '../../../src/utils.js' import * as dialogs from '@nextcloud/dialogs' jest.mock('@nextcloud/axios', () => { @@ -97,6 +97,7 @@ const selectors = { const completeIntegrationState = { openproject_instance_url: 'http://openproject.com', + authorization_method: AUTH_METHOD.OAUTH2, openproject_client_id: 'some-client-id-for-op', openproject_client_secret: 'some-client-secret-for-op', nc_oauth_client: { @@ -140,6 +141,7 @@ describe('AdminSettings.vue', () => { 'with incomplete OpenProject OAuth values', { openproject_instance_url: 'https://openproject.example.com', + authorization_method: AUTH_METHOD.OAUTH2, openproject_client_id: null, openproject_client_secret: null, nc_oauth_client: null, @@ -187,6 +189,7 @@ describe('AdminSettings.vue', () => { 'with everything but empty OpenProject OAuth values', { openproject_instance_url: 'https://openproject.example.com', + authorization_method: 'oauth2', openproject_client_id: null, openproject_client_secret: null, nc_oauth_client: { @@ -476,7 +479,7 @@ describe('AdminSettings.vue', () => { expect(wrapper.vm.formMode.server).toBe(F_MODES.EDIT) expect(wrapper.vm.isOpenProjectInstanceValid).toBe(null) - expect(wrapper.vm.formMode.opOauth).toBe(F_MODES.DISABLE) + expect(wrapper.vm.formMode.authorizationMethod).toBe(F_MODES.DISABLE) serverHostForm = wrapper.find(selectors.serverHostForm) await serverHostForm.find('input').setValue('http://openproject.com') @@ -492,7 +495,7 @@ describe('AdminSettings.vue', () => { expect(wrapper.vm.isFormCompleted.server).toBe(true) expect(setAdminConfigAPISpy).toBeCalledTimes(1) // should set the OpenProject OAuth Values form to edit mode - expect(wrapper.vm.formMode.opOauth).toBe(F_MODES.EDIT) + expect(wrapper.vm.formMode.authorizationMethod).toBe(F_MODES.EDIT) }) }) describe('disabled state', () => { @@ -556,6 +559,7 @@ describe('AdminSettings.vue', () => { wrapper = getMountedWrapper({ state: { openproject_instance_url: 'http://openproject.com', + authorization_method: AUTH_METHOD.OAUTH2, openproject_client_id: 'openproject-client-id', openproject_client_secret: 'openproject-client-secret', nc_oauth_client: null, @@ -616,6 +620,7 @@ describe('AdminSettings.vue', () => { wrapper = getMountedWrapper({ state: { openproject_instance_url: 'http://openproject.com', + authorization_method: AUTH_METHOD.OAUTH2, openproject_client_id: '', openproject_client_secret: '', nc_oauth_client: null, @@ -669,6 +674,7 @@ describe('AdminSettings.vue', () => { const wrapper = getMountedWrapper({ state: { openproject_instance_url: 'http://openproject.com', + authorization_method: AUTH_METHOD.OAUTH2, openproject_client_id: '', openproject_client_secret: '', nc_oauth_client: { @@ -1640,6 +1646,9 @@ describe('AdminSettings.vue', () => { nextcloud_client_id: 'something', nextcloud_client_secret: 'something-else', }, + authorization_settings: { + targeted_audience_client_id: null, + }, }, }) confirmSpy = jest.spyOn(global.OC.dialogs, 'confirmDestructive') @@ -1683,10 +1692,13 @@ describe('AdminSettings.vue', () => { openproject_client_id: null, openproject_client_secret: null, openproject_instance_url: null, + authorization_method: null, default_enable_navigation: false, default_enable_unified_search: false, - setup_app_password: false, + oidc_provider: null, setup_project_folder: false, + setup_app_password: false, + targeted_audience_client_id: null, }, }, ) @@ -1703,6 +1715,9 @@ describe('AdminSettings.vue', () => { nextcloud_client_id: 'something', nextcloud_client_secret: 'something-else', }, + authorization_settings: { + targeted_audience_client_id: null, + }, app_password_set: true, }, oPUserAppPassword: 'oPUserAppPassword', @@ -1719,10 +1734,13 @@ describe('AdminSettings.vue', () => { openproject_client_id: null, openproject_client_secret: null, openproject_instance_url: null, + authorization_method: null, default_enable_navigation: false, default_enable_unified_search: false, + oidc_provider: null, setup_project_folder: false, setup_app_password: false, + targeted_audience_client_id: null, }, }, ) diff --git a/tests/jest/components/PersonalSettings.spec.js b/tests/jest/components/PersonalSettings.spec.js index cf0584dd2..888a0f2dc 100644 --- a/tests/jest/components/PersonalSettings.spec.js +++ b/tests/jest/components/PersonalSettings.spec.js @@ -4,6 +4,7 @@ import { shallowMount, createLocalVue, mount } from '@vue/test-utils' import PersonalSettings from '../../../src/components/PersonalSettings.vue' import * as dialogs from '@nextcloud/dialogs' import axios from '@nextcloud/axios' +import { AUTH_METHOD } from '../../../src/utils.js' const localVue = createLocalVue() @@ -90,7 +91,7 @@ describe('PersonalSettings.vue', () => { describe('when username and token are given', () => { beforeEach(async () => { await wrapper.setData({ - state: { user_name: 'test', token: '123', admin_config_ok: true }, + state: { user_name: 'test', token: '123', admin_config_ok: true, authorization_method: AUTH_METHOD.OAUTH2 }, }) }) it('oAuth connect button is not displayed', () => { diff --git a/tests/jest/components/tab/EmptyContent.spec.js b/tests/jest/components/tab/EmptyContent.spec.js index cc7d35e52..7510147ea 100644 --- a/tests/jest/components/tab/EmptyContent.spec.js +++ b/tests/jest/components/tab/EmptyContent.spec.js @@ -1,7 +1,7 @@ /* jshint esversion: 8 */ import { shallowMount, createLocalVue } from '@vue/test-utils' import EmptyContent from '../../../../src/components/tab/EmptyContent.vue' -import { STATE } from '../../../../src/utils.js' +import { AUTH_METHOD, STATE } from '../../../../src/utils.js' const localVue = createLocalVue() describe('EmptyContent.vue', () => { @@ -55,6 +55,7 @@ function getWrapper(propsData = {}) { propsData: { state: 'ok', isAdminConfigOk: true, + authMethod: AUTH_METHOD.OAUTH2, ...propsData, }, })