Skip to content
Snippets Groups Projects
Commit 232e0a31 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 00fa950a
No related branches found
No related tags found
No related merge requests found
Showing
with 808 additions and 165 deletions
---
disqus_identifier: 'https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html'
type: reference, howto
---
 
Loading
Loading
---
disqus_identifier: 'https://docs.gitlab.com/ee/user/project/pipelines/schedules.html'
type: reference, howto
---
 
Loading
Loading
---
disqus_identifier: 'https://docs.gitlab.com/ee/user/project/pipelines/settings.html'
type: reference, howto
---
 
Loading
Loading
Loading
Loading
@@ -2264,6 +2264,25 @@ concatenated into a single file. Use a filename pattern (`junit: rspec-*.xml`),
an array of filenames (`junit: [rspec-1.xml, rspec-2.xml, rspec-3.xml]`), or a
combination thereof (`junit: [rspec.xml, test-results/TEST-*.xml]`).
 
##### `artifacts:reports:dotenv`
> [Introduced](https://gitlab.com/gitlab-org/gitlab/issues/17066) in GitLab 12.9. Requires GitLab Runner 11.5 and later.
The `dotenv` report collects a set of environment variables as artifacts.
The collected variables are registered as runtime-created variables of the job,
which is useful to [set dynamic environment URLs after a job finishes](../environments.md#set-dynamic-environment-urls-after-a-job-finishes).
It is not available for download through the web interface.
There are a couple of limitations on top of the [original dotenv rules](https://github.com/motdotla/dotenv#rules).
- The variable key can contain only letters, digits and underscore ('_').
- The size of dotenv file must be smaller than 5 kilobytes.
- The number of variables must be less than 10.
- It doesn't support variable substitution in the dotenv file itself.
- It doesn't support empty lines and comments (`#`) in dotenv file.
- It doesn't support quote escape, spaces in a quote, a new line expansion in a quote, in dotenv file.
##### `artifacts:reports:codequality` **(STARTER)**
 
> Introduced in GitLab 11.5. Requires GitLab Runner 11.5 and above.
Loading
Loading
Loading
Loading
@@ -39,6 +39,8 @@ To select your issue template for use within Incident Management:
GitLab can react to the alerts that your applications and services may be
triggering by automatically creating issues, and alerting developers via email.
 
The emails will be sent to [owners and maintainers](../permissions.md) of the project and will contain details on the alert as well as a link to see more information.
### Prometheus alerts
 
Prometheus alerts can be set up in both:
Loading
Loading
Loading
Loading
@@ -11,7 +11,10 @@ module Gitlab
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
 
ALLOWED_KEYS = %i[junit codequality sast dependency_scanning container_scanning dast performance license_management license_scanning metrics lsif].freeze
ALLOWED_KEYS =
%i[junit codequality sast dependency_scanning container_scanning
dast performance license_management license_scanning metrics lsif
dotenv].freeze
 
attributes ALLOWED_KEYS
 
Loading
Loading
@@ -31,6 +34,7 @@ module Gitlab
validates :license_scanning, array_of_strings_or_string: true
validates :metrics, array_of_strings_or_string: true
validates :lsif, array_of_strings_or_string: true
validates :dotenv, array_of_strings_or_string: true
end
end
 
Loading
Loading
Loading
Loading
@@ -1777,6 +1777,9 @@ msgstr ""
msgid "An error occurred while committing your changes."
msgstr ""
 
msgid "An error occurred while decoding the file."
msgstr ""
msgid "An error occurred while deleting the approvers group"
msgstr ""
 
Loading
Loading
@@ -1918,6 +1921,9 @@ msgstr ""
msgid "An error occurred while loading the file."
msgstr ""
 
msgid "An error occurred while loading the file. Please try again later."
msgstr ""
msgid "An error occurred while loading the merge request changes."
msgstr ""
 
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -6,5 +6,9 @@ FactoryBot.define do
value { 'VARIABLE_VALUE' }
 
job factory: :ci_build
trait :dotenv_source do
source { :dotenv }
end
end
end
File added
import { shallowMount } from '@vue/test-utils';
import { GlLoadingIcon } from '@gitlab/ui';
import { FIXTURES_PATH } from 'spec/test_constants';
import renderPDF from '~/blob/pdf';
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 viewer;
let app;
let wrapper;
 
const checkLoaded = done => {
if (app.loading) {
setTimeout(() => {
checkLoaded(done);
}, 100);
} else {
done();
}
const mountComponent = () => {
wrapper = shallowMount(component, {
propsData: {
pdf: testPDF,
},
});
};
 
preloadFixtures('static/pdf_viewer.html');
const findLoading = () => wrapper.find(GlLoadingIcon);
const findPdfLab = () => wrapper.find(PdfLab);
const findLoadError = () => wrapper.find({ ref: 'loadError' });
 
beforeEach(() => {
loadFixtures('static/pdf_viewer.html');
viewer = document.getElementById('js-pdf-viewer');
viewer.dataset.endpoint = testPDF;
mountComponent();
});
 
it('shows loading icon', () => {
renderPDF();
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
 
expect(document.querySelector('.loading')).not.toBeNull();
it('shows loading icon', () => {
expect(findLoading().exists()).toBe(true);
});
 
describe('successful response', () => {
beforeEach(done => {
app = renderPDF();
checkLoaded(done);
beforeEach(() => {
findPdfLab().vm.$emit('pdflabload');
});
 
it('does not show loading icon', () => {
expect(document.querySelector('.loading')).toBeNull();
expect(findLoading().exists()).toBe(false);
});
 
it('renders the PDF', () => {
expect(document.querySelector('.pdf-viewer')).not.toBeNull();
});
it('renders the PDF page', () => {
expect(document.querySelector('.pdf-page')).not.toBeNull();
expect(findPdfLab().exists()).toBe(true);
});
});
 
describe('error getting file', () => {
beforeEach(done => {
viewer.dataset.endpoint = 'invalid/path/to/file.pdf';
app = renderPDF();
checkLoaded(done);
beforeEach(() => {
findPdfLab().vm.$emit('pdflaberror', 'foo');
});
 
it('does not show loading icon', () => {
expect(document.querySelector('.loading')).toBeNull();
expect(findLoading().exists()).toBe(false);
});
 
it('shows error message', () => {
expect(document.querySelector('.md').textContent.trim()).toBe(
expect(findLoadError().text()).toBe(
'An error occurred while loading the file. Please try again later.',
);
});
Loading
Loading
<div class="file-content" data-endpoint="/test" id="js-pdf-viewer"></div>
Loading
Loading
@@ -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]);
});
});
});
Loading
Loading
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', () => {
Loading
Loading
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';
Loading
Loading
@@ -14,7 +13,6 @@ describe('Page component', () => {
let testPage;
 
beforeEach(done => {
pdfjsLib.GlobalWorkerOptions.workerSrc = workerSrc;
pdfjsLib
.getDocument(testPDF)
.promise.then(pdf => pdf.getPage(1))
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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) }
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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|
Loading
Loading
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment