diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-14 00:09:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-14 00:09:38 +0300 |
commit | 232e0a31f1e5d5b3a788dfc3dba8f8d41df36bf9 (patch) | |
tree | a2b11b9a805ef1165d8730934ba4a4f801f31870 /spec | |
parent | 00fa950a34b1c94617110b150b8b2517d5241249 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/job_artifacts.rb | 10 | ||||
-rw-r--r-- | spec/factories/ci/job_variables.rb | 4 | ||||
-rw-r--r-- | spec/fixtures/build.env.gz | bin | 0 -> 46 bytes | |||
-rw-r--r-- | spec/frontend/blob/pdf/pdf_viewer_spec.js | 67 | ||||
-rw-r--r-- | spec/frontend/fixtures/static/pdf_viewer.html | 1 | ||||
-rw-r--r-- | spec/frontend/lib/utils/common_utils_spec.js | 503 | ||||
-rw-r--r-- | spec/javascripts/blob/pdf/index_spec.js | 72 | ||||
-rw-r--r-- | spec/javascripts/pdf/index_spec.js | 3 | ||||
-rw-r--r-- | spec/javascripts/pdf/page_spec.js | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/reports_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/pages_domain_spec.rb | 5 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 43 | ||||
-rw-r--r-- | spec/services/ci/create_job_artifacts_service_spec.rb | 36 | ||||
-rw-r--r-- | spec/services/ci/parse_dotenv_artifact_service_spec.rb | 260 | ||||
-rw-r--r-- | spec/services/ci/retry_build_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/deployments/after_create_service_spec.rb | 20 | ||||
-rw-r--r-- | spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb | 5 |
17 files changed, 799 insertions, 237 deletions
diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb index 296215abfa0..e0942bf0ac3 100644 --- a/spec/factories/ci/job_artifacts.rb +++ b/spec/factories/ci/job_artifacts.rb @@ -149,6 +149,16 @@ FactoryBot.define do end end + trait :dotenv do + file_type { :dotenv } + file_format { :gzip } + + after(:build) do |artifact, evaluator| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/build.env.gz'), 'application/x-gzip') + end + end + trait :correct_checksum do after(:build) do |artifact, evaluator| artifact.file_sha256 = Digest::SHA256.file(artifact.file.path).hexdigest diff --git a/spec/factories/ci/job_variables.rb b/spec/factories/ci/job_variables.rb index 472a89d3bef..ae2b89ad98d 100644 --- a/spec/factories/ci/job_variables.rb +++ b/spec/factories/ci/job_variables.rb @@ -6,5 +6,9 @@ FactoryBot.define do value { 'VARIABLE_VALUE' } job factory: :ci_build + + trait :dotenv_source do + source { :dotenv } + end end end diff --git a/spec/fixtures/build.env.gz b/spec/fixtures/build.env.gz Binary files differnew file mode 100644 index 00000000000..39ad1e17ffe --- /dev/null +++ b/spec/fixtures/build.env.gz diff --git a/spec/frontend/blob/pdf/pdf_viewer_spec.js b/spec/frontend/blob/pdf/pdf_viewer_spec.js new file mode 100644 index 00000000000..0eea3aea639 --- /dev/null +++ b/spec/frontend/blob/pdf/pdf_viewer_spec.js @@ -0,0 +1,67 @@ +import { shallowMount } from '@vue/test-utils'; +import { GlLoadingIcon } from '@gitlab/ui'; + +import { FIXTURES_PATH } from 'spec/test_constants'; +import component from '~/blob/pdf/pdf_viewer.vue'; +import PdfLab from '~/pdf/index.vue'; + +const testPDF = `${FIXTURES_PATH}/blob/pdf/test.pdf`; + +describe('PDF renderer', () => { + let wrapper; + + const mountComponent = () => { + wrapper = shallowMount(component, { + propsData: { + pdf: testPDF, + }, + }); + }; + + const findLoading = () => wrapper.find(GlLoadingIcon); + const findPdfLab = () => wrapper.find(PdfLab); + const findLoadError = () => wrapper.find({ ref: 'loadError' }); + + beforeEach(() => { + mountComponent(); + }); + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + it('shows loading icon', () => { + expect(findLoading().exists()).toBe(true); + }); + + describe('successful response', () => { + beforeEach(() => { + findPdfLab().vm.$emit('pdflabload'); + }); + + it('does not show loading icon', () => { + expect(findLoading().exists()).toBe(false); + }); + + it('renders the PDF', () => { + expect(findPdfLab().exists()).toBe(true); + }); + }); + + describe('error getting file', () => { + beforeEach(() => { + findPdfLab().vm.$emit('pdflaberror', 'foo'); + }); + + it('does not show loading icon', () => { + expect(findLoading().exists()).toBe(false); + }); + + it('shows error message', () => { + expect(findLoadError().text()).toBe( + 'An error occurred while loading the file. Please try again later.', + ); + }); + }); +}); diff --git a/spec/frontend/fixtures/static/pdf_viewer.html b/spec/frontend/fixtures/static/pdf_viewer.html deleted file mode 100644 index 350d35a262f..00000000000 --- a/spec/frontend/fixtures/static/pdf_viewer.html +++ /dev/null @@ -1 +0,0 @@ -<div class="file-content" data-endpoint="/test" id="js-pdf-viewer"></div> diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js index d0d45b153af..6ba8f58086a 100644 --- a/spec/frontend/lib/utils/common_utils_spec.js +++ b/spec/frontend/lib/utils/common_utils_spec.js @@ -539,193 +539,382 @@ describe('common_utils', () => { }); }); - describe('convertObjectPropsToCamelCase', () => { - it('returns new object with camelCase property names by converting object with snake_case names', () => { - const snakeRegEx = /(_\w)/g; - const mockObj = { - id: 1, - group_name: 'GitLab.org', - absolute_web_url: 'https://gitlab.com/gitlab-org/', - }; - const mappings = { - id: 'id', - groupName: 'group_name', - absoluteWebUrl: 'absolute_web_url', - }; + describe('convertObjectProps*', () => { + const mockConversionFunction = prop => `${prop}_converted`; + const isEmptyObject = obj => + typeof obj === 'object' && obj !== null && Object.keys(obj).length === 0; + + const mockObjects = { + convertObjectProps: { + obj: { + id: 1, + group_name: 'GitLab.org', + absolute_web_url: 'https://gitlab.com/gitlab-org/', + }, + objNested: { + project_name: 'GitLab CE', + group_name: 'GitLab.org', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, + }, + }, + convertObjectPropsToCamelCase: { + obj: { + id: 1, + group_name: 'GitLab.org', + absolute_web_url: 'https://gitlab.com/gitlab-org/', + }, + objNested: { + project_name: 'GitLab CE', + group_name: 'GitLab.org', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, + }, + }, + convertObjectPropsToSnakeCase: { + obj: { + id: 1, + groupName: 'GitLab.org', + absoluteWebUrl: 'https://gitlab.com/gitlab-org/', + }, + objNested: { + projectName: 'GitLab CE', + groupName: 'GitLab.org', + licenseType: 'MIT', + techStack: { + backend: 'Ruby', + frontendFramework: 'Vue', + database: 'PostgreSQL', + }, + }, + }, + }; - const convertedObj = commonUtils.convertObjectPropsToCamelCase(mockObj); + describe('convertObjectProps', () => { + it('returns an empty object if `conversionFunction` parameter is not a function', () => { + const result = commonUtils.convertObjectProps(null, mockObjects.convertObjectProps.obj); - Object.keys(convertedObj).forEach(prop => { - expect(snakeRegEx.test(prop)).toBeFalsy(); - expect(convertedObj[prop]).toBe(mockObj[mappings[prop]]); + expect(isEmptyObject(result)).toBeTruthy(); }); }); - it('return empty object if method is called with null or undefined', () => { - expect(Object.keys(commonUtils.convertObjectPropsToCamelCase(null)).length).toBe(0); - expect(Object.keys(commonUtils.convertObjectPropsToCamelCase()).length).toBe(0); - expect(Object.keys(commonUtils.convertObjectPropsToCamelCase({})).length).toBe(0); - }); - - it('does not deep-convert by default', () => { - const obj = { - snake_key: { - child_snake_key: 'value', - }, - }; - - expect(commonUtils.convertObjectPropsToCamelCase(obj)).toEqual({ - snakeKey: { - child_snake_key: 'value', - }, + describe.each` + functionName | mockObj | mockObjNested + ${'convertObjectProps'} | ${mockObjects.convertObjectProps.obj} | ${mockObjects.convertObjectProps.objNested} + ${'convertObjectPropsToCamelCase'} | ${mockObjects.convertObjectPropsToCamelCase.obj} | ${mockObjects.convertObjectPropsToCamelCase.objNested} + ${'convertObjectPropsToSnakeCase'} | ${mockObjects.convertObjectPropsToSnakeCase.obj} | ${mockObjects.convertObjectPropsToSnakeCase.objNested} + `('$functionName', ({ functionName, mockObj, mockObjNested }) => { + const testFunction = + functionName === 'convertObjectProps' + ? (obj, options = {}) => + commonUtils.convertObjectProps(mockConversionFunction, obj, options) + : commonUtils[functionName]; + + it('returns an empty object if `obj` parameter is null, undefined or an empty object', () => { + expect(isEmptyObject(testFunction(null))).toBeTruthy(); + expect(isEmptyObject(testFunction())).toBeTruthy(); + expect(isEmptyObject(testFunction({}))).toBeTruthy(); }); - }); - describe('convertObjectPropsToSnakeCase', () => { - it('converts each object key to snake case', () => { - const obj = { - some: 'some', - 'cool object': 'cool object', - likeThisLongOne: 'likeThisLongOne', + it('converts object properties', () => { + const expected = { + convertObjectProps: { + id_converted: 1, + group_name_converted: 'GitLab.org', + absolute_web_url_converted: 'https://gitlab.com/gitlab-org/', + }, + convertObjectPropsToCamelCase: { + id: 1, + groupName: 'GitLab.org', + absoluteWebUrl: 'https://gitlab.com/gitlab-org/', + }, + convertObjectPropsToSnakeCase: { + id: 1, + group_name: 'GitLab.org', + absolute_web_url: 'https://gitlab.com/gitlab-org/', + }, }; - expect(commonUtils.convertObjectPropsToSnakeCase(obj)).toEqual({ - some: 'some', - cool_object: 'cool object', - like_this_long_one: 'likeThisLongOne', - }); + expect(testFunction(mockObj)).toEqual(expected[functionName]); }); - it('returns an empty object if there are no keys', () => { - ['', {}, [], null].forEach(badObj => { - expect(commonUtils.convertObjectPropsToSnakeCase(badObj)).toEqual({}); - }); - }); - }); - - describe('with options', () => { - const objWithoutChildren = { - project_name: 'GitLab CE', - group_name: 'GitLab.org', - license_type: 'MIT', - }; + it('does not deep-convert by default', () => { + const expected = { + convertObjectProps: { + project_name_converted: 'GitLab CE', + group_name_converted: 'GitLab.org', + license_type_converted: 'MIT', + tech_stack_converted: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, + }, + convertObjectPropsToCamelCase: { + projectName: 'GitLab CE', + groupName: 'GitLab.org', + licenseType: 'MIT', + techStack: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, + }, + convertObjectPropsToSnakeCase: { + project_name: 'GitLab CE', + group_name: 'GitLab.org', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontendFramework: 'Vue', + database: 'PostgreSQL', + }, + }, + }; - const objWithChildren = { - project_name: 'GitLab CE', - group_name: 'GitLab.org', - license_type: 'MIT', - tech_stack: { - backend: 'Ruby', - frontend_framework: 'Vue', - database: 'PostgreSQL', - }, - }; + expect(testFunction(mockObjNested)).toEqual(expected[functionName]); + }); - describe('when options.deep is true', () => { - it('converts object with child objects', () => { - const obj = { - snake_key: { - child_snake_key: 'value', + describe('with options', () => { + describe('when options.deep is true', () => { + const expected = { + convertObjectProps: { + project_name_converted: 'GitLab CE', + group_name_converted: 'GitLab.org', + license_type_converted: 'MIT', + tech_stack_converted: { + backend_converted: 'Ruby', + frontend_framework_converted: 'Vue', + database_converted: 'PostgreSQL', + }, + }, + convertObjectPropsToCamelCase: { + projectName: 'GitLab CE', + groupName: 'GitLab.org', + licenseType: 'MIT', + techStack: { + backend: 'Ruby', + frontendFramework: 'Vue', + database: 'PostgreSQL', + }, + }, + convertObjectPropsToSnakeCase: { + project_name: 'GitLab CE', + group_name: 'GitLab.org', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, }, }; - expect(commonUtils.convertObjectPropsToCamelCase(obj, { deep: true })).toEqual({ - snakeKey: { - childSnakeKey: 'value', - }, + it('converts nested objects', () => { + expect(testFunction(mockObjNested, { deep: true })).toEqual(expected[functionName]); }); - }); - it('converts array with child objects', () => { - const arr = [ - { - child_snake_key: 'value', - }, - ]; + it('converts array of nested objects', () => { + expect(testFunction([mockObjNested], { deep: true })).toEqual([expected[functionName]]); + }); - expect(commonUtils.convertObjectPropsToCamelCase(arr, { deep: true })).toEqual([ - { - childSnakeKey: 'value', - }, - ]); + it('converts array with child arrays', () => { + expect(testFunction([[mockObjNested]], { deep: true })).toEqual([ + [expected[functionName]], + ]); + }); }); - it('converts array with child arrays', () => { - const arr = [ - [ - { - child_snake_key: 'value', + describe('when options.dropKeys is provided', () => { + it('discards properties mentioned in `dropKeys` array', () => { + const expected = { + convertObjectProps: { + project_name_converted: 'GitLab CE', + license_type_converted: 'MIT', + tech_stack_converted: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, }, - ], - ]; - - expect(commonUtils.convertObjectPropsToCamelCase(arr, { deep: true })).toEqual([ - [ - { - childSnakeKey: 'value', + convertObjectPropsToCamelCase: { + projectName: 'GitLab CE', + licenseType: 'MIT', + techStack: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, }, - ], - ]); - }); - }); - - describe('when options.dropKeys is provided', () => { - it('discards properties mentioned in `dropKeys` array', () => { - expect( - commonUtils.convertObjectPropsToCamelCase(objWithoutChildren, { - dropKeys: ['group_name'], - }), - ).toEqual({ - projectName: 'GitLab CE', - licenseType: 'MIT', + convertObjectPropsToSnakeCase: { + project_name: 'GitLab CE', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontendFramework: 'Vue', + database: 'PostgreSQL', + }, + }, + }; + + const dropKeys = { + convertObjectProps: ['group_name'], + convertObjectPropsToCamelCase: ['group_name'], + convertObjectPropsToSnakeCase: ['groupName'], + }; + + expect( + testFunction(mockObjNested, { + dropKeys: dropKeys[functionName], + }), + ).toEqual(expected[functionName]); }); - }); - it('discards properties mentioned in `dropKeys` array when `deep` is true', () => { - expect( - commonUtils.convertObjectPropsToCamelCase(objWithChildren, { - deep: true, - dropKeys: ['group_name', 'database'], - }), - ).toEqual({ - projectName: 'GitLab CE', - licenseType: 'MIT', - techStack: { - backend: 'Ruby', - frontendFramework: 'Vue', - }, + it('discards properties mentioned in `dropKeys` array when `deep` is true', () => { + const expected = { + convertObjectProps: { + project_name_converted: 'GitLab CE', + license_type_converted: 'MIT', + tech_stack_converted: { + backend_converted: 'Ruby', + frontend_framework_converted: 'Vue', + }, + }, + convertObjectPropsToCamelCase: { + projectName: 'GitLab CE', + licenseType: 'MIT', + techStack: { + backend: 'Ruby', + frontendFramework: 'Vue', + }, + }, + convertObjectPropsToSnakeCase: { + project_name: 'GitLab CE', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontend_framework: 'Vue', + }, + }, + }; + + const dropKeys = { + convertObjectProps: ['group_name', 'database'], + convertObjectPropsToCamelCase: ['group_name', 'database'], + convertObjectPropsToSnakeCase: ['groupName', 'database'], + }; + + expect( + testFunction(mockObjNested, { + dropKeys: dropKeys[functionName], + deep: true, + }), + ).toEqual(expected[functionName]); }); }); - }); - describe('when options.ignoreKeyNames is provided', () => { - it('leaves properties mentioned in `ignoreKeyNames` array intact', () => { - expect( - commonUtils.convertObjectPropsToCamelCase(objWithoutChildren, { - ignoreKeyNames: ['group_name'], - }), - ).toEqual({ - projectName: 'GitLab CE', - licenseType: 'MIT', - group_name: 'GitLab.org', + describe('when options.ignoreKeyNames is provided', () => { + it('leaves properties mentioned in `ignoreKeyNames` array intact', () => { + const expected = { + convertObjectProps: { + project_name_converted: 'GitLab CE', + group_name: 'GitLab.org', + license_type_converted: 'MIT', + tech_stack_converted: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, + }, + convertObjectPropsToCamelCase: { + projectName: 'GitLab CE', + group_name: 'GitLab.org', + licenseType: 'MIT', + techStack: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, + }, + convertObjectPropsToSnakeCase: { + project_name: 'GitLab CE', + groupName: 'GitLab.org', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontendFramework: 'Vue', + database: 'PostgreSQL', + }, + }, + }; + + const ignoreKeyNames = { + convertObjectProps: ['group_name'], + convertObjectPropsToCamelCase: ['group_name'], + convertObjectPropsToSnakeCase: ['groupName'], + }; + + expect( + testFunction(mockObjNested, { + ignoreKeyNames: ignoreKeyNames[functionName], + }), + ).toEqual(expected[functionName]); }); - }); - it('leaves properties mentioned in `ignoreKeyNames` array intact when `deep` is true', () => { - expect( - commonUtils.convertObjectPropsToCamelCase(objWithChildren, { - deep: true, - ignoreKeyNames: ['group_name', 'frontend_framework'], - }), - ).toEqual({ - projectName: 'GitLab CE', - group_name: 'GitLab.org', - licenseType: 'MIT', - techStack: { - backend: 'Ruby', - frontend_framework: 'Vue', - database: 'PostgreSQL', - }, + it('leaves properties mentioned in `ignoreKeyNames` array intact when `deep` is true', () => { + const expected = { + convertObjectProps: { + project_name_converted: 'GitLab CE', + group_name: 'GitLab.org', + license_type_converted: 'MIT', + tech_stack_converted: { + backend_converted: 'Ruby', + frontend_framework: 'Vue', + database_converted: 'PostgreSQL', + }, + }, + convertObjectPropsToCamelCase: { + projectName: 'GitLab CE', + group_name: 'GitLab.org', + licenseType: 'MIT', + techStack: { + backend: 'Ruby', + frontend_framework: 'Vue', + database: 'PostgreSQL', + }, + }, + convertObjectPropsToSnakeCase: { + project_name: 'GitLab CE', + groupName: 'GitLab.org', + license_type: 'MIT', + tech_stack: { + backend: 'Ruby', + frontendFramework: 'Vue', + database: 'PostgreSQL', + }, + }, + }; + + const ignoreKeyNames = { + convertObjectProps: ['group_name', 'frontend_framework'], + convertObjectPropsToCamelCase: ['group_name', 'frontend_framework'], + convertObjectPropsToSnakeCase: ['groupName', 'frontendFramework'], + }; + + expect( + testFunction(mockObjNested, { + deep: true, + ignoreKeyNames: ignoreKeyNames[functionName], + }), + ).toEqual(expected[functionName]); }); }); }); diff --git a/spec/javascripts/blob/pdf/index_spec.js b/spec/javascripts/blob/pdf/index_spec.js deleted file mode 100644 index 66769a8aa47..00000000000 --- a/spec/javascripts/blob/pdf/index_spec.js +++ /dev/null @@ -1,72 +0,0 @@ -import { FIXTURES_PATH } from 'spec/test_constants'; -import renderPDF from '~/blob/pdf'; - -const testPDF = `${FIXTURES_PATH}/blob/pdf/test.pdf`; - -describe('PDF renderer', () => { - let viewer; - let app; - - const checkLoaded = done => { - if (app.loading) { - setTimeout(() => { - checkLoaded(done); - }, 100); - } else { - done(); - } - }; - - preloadFixtures('static/pdf_viewer.html'); - - beforeEach(() => { - loadFixtures('static/pdf_viewer.html'); - viewer = document.getElementById('js-pdf-viewer'); - viewer.dataset.endpoint = testPDF; - }); - - it('shows loading icon', () => { - renderPDF(); - - expect(document.querySelector('.loading')).not.toBeNull(); - }); - - describe('successful response', () => { - beforeEach(done => { - app = renderPDF(); - - checkLoaded(done); - }); - - it('does not show loading icon', () => { - expect(document.querySelector('.loading')).toBeNull(); - }); - - it('renders the PDF', () => { - expect(document.querySelector('.pdf-viewer')).not.toBeNull(); - }); - - it('renders the PDF page', () => { - expect(document.querySelector('.pdf-page')).not.toBeNull(); - }); - }); - - describe('error getting file', () => { - beforeEach(done => { - viewer.dataset.endpoint = 'invalid/path/to/file.pdf'; - app = renderPDF(); - - checkLoaded(done); - }); - - it('does not show loading icon', () => { - expect(document.querySelector('.loading')).toBeNull(); - }); - - it('shows error message', () => { - expect(document.querySelector('.md').textContent.trim()).toBe( - 'An error occurred while loading the file. Please try again later.', - ); - }); - }); -}); diff --git a/spec/javascripts/pdf/index_spec.js b/spec/javascripts/pdf/index_spec.js index e14f1b27f6c..39cd4dacd70 100644 --- a/spec/javascripts/pdf/index_spec.js +++ b/spec/javascripts/pdf/index_spec.js @@ -1,13 +1,10 @@ import Vue from 'vue'; -import { GlobalWorkerOptions } from 'pdfjs-dist/build/pdf'; -import workerSrc from 'pdfjs-dist/build/pdf.worker.min'; import { FIXTURES_PATH } from 'spec/test_constants'; import PDFLab from '~/pdf/index.vue'; const pdf = `${FIXTURES_PATH}/blob/pdf/test.pdf`; -GlobalWorkerOptions.workerSrc = workerSrc; const Component = Vue.extend(PDFLab); describe('PDF component', () => { diff --git a/spec/javascripts/pdf/page_spec.js b/spec/javascripts/pdf/page_spec.js index bb2294e8d18..cc2cc204ee3 100644 --- a/spec/javascripts/pdf/page_spec.js +++ b/spec/javascripts/pdf/page_spec.js @@ -1,6 +1,5 @@ import Vue from 'vue'; -import pdfjsLib from 'pdfjs-dist/build/pdf'; -import workerSrc from 'pdfjs-dist/build/pdf.worker.min'; +import pdfjsLib from 'pdfjs-dist/webpack'; import mountComponent from 'spec/helpers/vue_mount_component_helper'; import { FIXTURES_PATH } from 'spec/test_constants'; @@ -14,7 +13,6 @@ describe('Page component', () => { let testPage; beforeEach(done => { - pdfjsLib.GlobalWorkerOptions.workerSrc = workerSrc; pdfjsLib .getDocument(testPDF) .promise.then(pdf => pdf.getPage(1)) diff --git a/spec/lib/gitlab/ci/config/entry/reports_spec.rb b/spec/lib/gitlab/ci/config/entry/reports_spec.rb index c64bb0a4cc3..31e1aaa42bf 100644 --- a/spec/lib/gitlab/ci/config/entry/reports_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/reports_spec.rb @@ -44,6 +44,7 @@ describe Gitlab::Ci::Config::Entry::Reports do :license_scanning | 'gl-license-scanning-report.json' :performance | 'performance.json' :lsif | 'lsif.json' + :dotenv | 'build.dotenv' end with_them do diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index 33459767302..a4ed02c3254 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -7,6 +7,11 @@ describe PagesDomain do subject(:pages_domain) { described_class.new } + # Locking in date due to cert expiration date https://gitlab.com/gitlab-org/gitlab/-/issues/210557#note_304749257 + around do |example| + Timecop.travel(Time.new(2020, 3, 12)) { example.run } + end + describe 'associations' do it { is_expected.to belong_to(:project) } it { is_expected.to have_many(:serverless_domain_clusters) } diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 6e5c2088ee7..5a8add1e9db 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -1937,6 +1937,49 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end end + + context 'when artifact_type is dotenv' do + context 'when artifact_format is gzip' do + let(:file_upload) { fixture_file_upload('spec/fixtures/build.env.gz') } + let(:params) { { artifact_type: :dotenv, artifact_format: :gzip } } + + it 'stores dotenv file' do + upload_artifacts(file_upload, headers_with_token, params) + + expect(response).to have_gitlab_http_status(:created) + expect(job.reload.job_artifacts_dotenv).not_to be_nil + end + + it 'parses dotenv file' do + expect do + upload_artifacts(file_upload, headers_with_token, params) + end.to change { job.job_variables.count }.from(0).to(2) + end + + context 'when parse error happens' do + let(:file_upload) { fixture_file_upload('spec/fixtures/ci_build_artifacts_metadata.gz') } + + it 'returns an error' do + upload_artifacts(file_upload, headers_with_token, params) + + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response['message']).to eq('Invalid Format') + end + end + end + + context 'when artifact_format is raw' do + let(:file_upload) { fixture_file_upload('spec/fixtures/build.env.gz') } + let(:params) { { artifact_type: :dotenv, artifact_format: :raw } } + + it 'returns an error' do + upload_artifacts(file_upload, headers_with_token, params) + + expect(response).to have_gitlab_http_status(:bad_request) + expect(job.reload.job_artifacts_dotenv).to be_nil + end + end + end end context 'when artifacts already exist for the job' do diff --git a/spec/services/ci/create_job_artifacts_service_spec.rb b/spec/services/ci/create_job_artifacts_service_spec.rb index 03106687678..fe64a66f322 100644 --- a/spec/services/ci/create_job_artifacts_service_spec.rb +++ b/spec/services/ci/create_job_artifacts_service_spec.rb @@ -121,6 +121,42 @@ describe Ci::CreateJobArtifactsService do end end + context 'when artifact type is dotenv' do + let(:artifacts_file) do + file_to_upload('spec/fixtures/build.env.gz', sha256: artifacts_sha256) + end + + let(:params) do + { + 'artifact_type' => 'dotenv', + 'artifact_format' => 'gzip' + } + end + + it 'calls parse service' do + expect_any_instance_of(Ci::ParseDotenvArtifactService) do |service| + expect(service).to receive(:execute).once.and_call_original + end + + expect(subject[:status]).to eq(:success) + expect(job.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => 'VAR1', 'source' => 'dotenv'), + hash_including('key' => 'KEY2', 'value' => 'VAR2', 'source' => 'dotenv')) + end + + context 'when ci_synchronous_artifact_parsing feature flag is disabled' do + before do + stub_feature_flags(ci_synchronous_artifact_parsing: false) + end + + it 'does not call parse service' do + expect(Ci::ParseDotenvArtifactService).not_to receive(:new) + + expect(subject[:status]).to eq(:success) + end + end + end + shared_examples 'rescues object storage error' do |klass, message, expected_message| it "handles #{klass}" do allow_next_instance_of(JobArtifactUploader) do |uploader| diff --git a/spec/services/ci/parse_dotenv_artifact_service_spec.rb b/spec/services/ci/parse_dotenv_artifact_service_spec.rb new file mode 100644 index 00000000000..fc4131d262b --- /dev/null +++ b/spec/services/ci/parse_dotenv_artifact_service_spec.rb @@ -0,0 +1,260 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::ParseDotenvArtifactService do + let_it_be(:project) { create(:project) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, pipeline: pipeline, project: project) } + let(:service) { described_class.new(project, nil) } + + describe '#execute' do + subject { service.execute(artifact) } + + context 'when build has a dotenv artifact' do + let!(:artifact) { create(:ci_job_artifact, :dotenv, job: build) } + + it 'parses the artifact' do + expect(subject[:status]).to eq(:success) + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => 'VAR1'), + hash_including('key' => 'KEY2', 'value' => 'VAR2')) + end + + context 'when parse error happens' do + before do + allow(service).to receive(:scan_line!) { raise described_class::ParserError.new('Invalid Format') } + end + + it 'returns error' do + expect(Gitlab::ErrorTracking).to receive(:track_exception) + .with(described_class::ParserError, job_id: build.id) + + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Invalid Format') + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when artifact size is too big' do + before do + allow(artifact.file).to receive(:size) { 10.kilobytes } + end + + it 'returns error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq("Dotenv Artifact Too Big. Maximum Allowable Size: #{described_class::MAX_ACCEPTABLE_DOTENV_SIZE}") + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when artifact has the specified blob' do + before do + allow(artifact).to receive(:each_blob).and_yield(blob) + end + + context 'when a white space trails the key' do + let(:blob) { 'KEY1 =VAR1' } + + it 'trims the trailing space' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => 'VAR1')) + end + end + + context 'when multiple key/value pairs exist in one line' do + let(:blob) { 'KEY1=VAR1KEY2=VAR1' } + + it 'returns error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq("Validation failed: Key can contain only letters, digits and '_'.") + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when key contains UNICODE' do + let(:blob) { '🛹=skateboard' } + + it 'returns error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq("Validation failed: Key can contain only letters, digits and '_'.") + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when value contains UNICODE' do + let(:blob) { 'skateboard=🛹' } + + it 'parses the dotenv data' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'skateboard', 'value' => '🛹')) + end + end + + context 'when key contains a space' do + let(:blob) { 'K E Y 1=VAR1' } + + it 'returns error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq("Validation failed: Key can contain only letters, digits and '_'.") + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when value contains a space' do + let(:blob) { 'KEY1=V A R 1' } + + it 'parses the dotenv data' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => 'V A R 1')) + end + end + + context 'when value is double quoated' do + let(:blob) { 'KEY1="VAR1"' } + + it 'parses the value as-is' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => '"VAR1"')) + end + end + + context 'when value is single quoated' do + let(:blob) { "KEY1='VAR1'" } + + it 'parses the value as-is' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => "'VAR1'")) + end + end + + context 'when value has white spaces in double quote' do + let(:blob) { 'KEY1=" VAR1 "' } + + it 'parses the value as-is' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => '" VAR1 "')) + end + end + + context 'when key is missing' do + let(:blob) { '=VAR1' } + + it 'returns error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to match(/Key can't be blank/) + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when value is missing' do + let(:blob) { 'KEY1=' } + + it 'parses the dotenv data' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => '')) + end + end + + context 'when it is not dotenv format' do + let(:blob) { "{ 'KEY1': 'VAR1' }" } + + it 'returns error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Invalid Format') + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when more than limitated variables are specified in dotenv' do + let(:blob) do + StringIO.new.tap do |s| + (described_class::MAX_ACCEPTABLE_VARIABLES_COUNT + 1).times do |i| + s << "KEY#{i}=VAR#{i}\n" + end + end.string + end + + it 'returns error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq("Dotenv files cannot have more than #{described_class::MAX_ACCEPTABLE_VARIABLES_COUNT} variables") + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when variables are cross-referenced in dotenv' do + let(:blob) do + <<~EOS + KEY1=VAR1 + KEY2=${KEY1}_Test + EOS + end + + it 'does not support variable expansion in dotenv parser' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => 'VAR1'), + hash_including('key' => 'KEY2', 'value' => '${KEY1}_Test')) + end + end + + context 'when there is an empty line' do + let(:blob) do + <<~EOS + KEY1=VAR1 + + KEY2=VAR2 + EOS + end + + it 'does not support empty line in dotenv parser' do + subject + + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq('Invalid Format') + expect(subject[:http_status]).to eq(:bad_request) + end + end + + context 'when there is a comment' do + let(:blob) do + <<~EOS + KEY1=VAR1 # This is variable + EOS + end + + it 'does not support comment in dotenv parser' do + subject + + expect(build.job_variables.as_json).to contain_exactly( + hash_including('key' => 'KEY1', 'value' => 'VAR1 # This is variable')) + end + end + end + end + + context 'when build does not have a dotenv artifact' do + let!(:artifact) { } + + it 'raises an error' do + expect { subject }.to raise_error(ArgumentError) + end + end + end +end diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index 8a22b2c8da3..6cecab8656a 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -36,7 +36,7 @@ describe Ci::RetryBuildService do job_artifacts_performance job_artifacts_lsif job_artifacts_codequality job_artifacts_metrics scheduled_at job_variables waiting_for_resource_at job_artifacts_metrics_referee - job_artifacts_network_referee needs].freeze + job_artifacts_network_referee job_artifacts_dotenv needs].freeze IGNORE_ACCESSORS = %i[type lock_version target_url base_tags trace_sections diff --git a/spec/services/deployments/after_create_service_spec.rb b/spec/services/deployments/after_create_service_spec.rb index 3aa137a866e..5a69ffd8b9c 100644 --- a/spec/services/deployments/after_create_service_spec.rb +++ b/spec/services/deployments/after_create_service_spec.rb @@ -177,6 +177,26 @@ describe Deployments::AfterCreateService do it { is_expected.to eq('http://review/host') } end + context 'when job variables are generated during runtime' do + let(:job) do + create(:ci_build, + :with_deployment, + pipeline: pipeline, + environment: 'review/$CI_COMMIT_REF_NAME', + project: project, + job_variables: [job_variable], + options: { environment: { name: 'review/$CI_COMMIT_REF_NAME', url: 'http://$DYNAMIC_ENV_URL' } }) + end + + let(:job_variable) do + build(:ci_job_variable, :dotenv_source, key: 'DYNAMIC_ENV_URL', value: 'abc.test.com') + end + + it 'expands the environment URL from the dynamic variable' do + is_expected.to eq('http://abc.test.com') + end + end + context 'when yaml environment does not have url' do let(:job) { create(:ci_build, :with_deployment, pipeline: pipeline, environment: 'staging', project: project) } diff --git a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb index 736acc40371..ae66122b4de 100644 --- a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb +++ b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb @@ -7,6 +7,11 @@ describe PagesDomainSslRenewalCronWorker do subject(:worker) { described_class.new } + # Locking in date due to cert expiration date https://gitlab.com/gitlab-org/gitlab/-/issues/210557#note_304749257 + around do |example| + Timecop.travel(Time.new(2020, 3, 12)) { example.run } + end + before do stub_lets_encrypt_settings end |