1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Appearance, 'Appearance' do
let_it_be(:user) { create(:user) }
let_it_be(:admin) { create(:admin) }
describe "GET /application/appearance" do
context 'as a non-admin user' do
it "returns 403" do
get api("/application/appearance", user)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'as an admin user' do
it "returns appearance" do
get api("/application/appearance", admin)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_an Hash
expect(json_response['description']).to eq('')
expect(json_response['email_header_and_footer_enabled']).to be(false)
expect(json_response['favicon']).to be_nil
expect(json_response['footer_message']).to eq('')
expect(json_response['header_logo']).to be_nil
expect(json_response['header_message']).to eq('')
expect(json_response['logo']).to be_nil
expect(json_response['message_background_color']).to eq('#E75E40')
expect(json_response['message_font_color']).to eq('#FFFFFF')
expect(json_response['new_project_guidelines']).to eq('')
expect(json_response['profile_image_guidelines']).to eq('')
expect(json_response['title']).to eq('')
end
end
end
describe "PUT /application/appearance" do
context 'as a non-admin user' do
it "returns 403" do
put api("/application/appearance", user), params: { title: "Test" }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'as an admin user' do
context "instance basics" do
it "allows updating the settings" do
put api("/application/appearance", admin), params: {
title: "GitLab Test Instance",
description: "gitlab-test.example.com",
new_project_guidelines: "Please read the FAQs for help.",
profile_image_guidelines: "Custom profile image guidelines"
}
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_an Hash
expect(json_response['description']).to eq('gitlab-test.example.com')
expect(json_response['email_header_and_footer_enabled']).to be(false)
expect(json_response['favicon']).to be_nil
expect(json_response['footer_message']).to eq('')
expect(json_response['header_logo']).to be_nil
expect(json_response['header_message']).to eq('')
expect(json_response['logo']).to be_nil
expect(json_response['message_background_color']).to eq('#E75E40')
expect(json_response['message_font_color']).to eq('#FFFFFF')
expect(json_response['new_project_guidelines']).to eq('Please read the FAQs for help.')
expect(json_response['profile_image_guidelines']).to eq('Custom profile image guidelines')
expect(json_response['title']).to eq('GitLab Test Instance')
end
end
context "system header and footer" do
it "allows updating the settings" do
settings = {
footer_message: "This is a Header",
header_message: "This is a Footer",
message_font_color: "#ffffff",
message_background_color: "#009999",
email_header_and_footer_enabled: true
}
put api("/application/appearance", admin), params: settings
expect(response).to have_gitlab_http_status(:ok)
settings.each do |attribute, value|
expect(Appearance.current.public_send(attribute)).to eq(value)
end
end
context "fails on invalid color values" do
it "with message_font_color" do
put api("/application/appearance", admin), params: { message_font_color: "No Color" }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['message_font_color']).to contain_exactly('must be a valid color code')
end
it "with message_background_color" do
put api("/application/appearance", admin), params: { message_background_color: "#1" }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['message_background_color']).to contain_exactly('must be a valid color code')
end
end
end
context "instance logos" do
let_it_be(:appearance) { create(:appearance) }
it "allows updating the image files" do
put api("/application/appearance", admin), params: {
logo: fixture_file_upload("spec/fixtures/dk.png", "image/png"),
header_logo: fixture_file_upload("spec/fixtures/dk.png", "image/png"),
favicon: fixture_file_upload("spec/fixtures/dk.png", "image/png")
}
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['logo']).to eq("/uploads/-/system/appearance/logo/#{appearance.id}/dk.png")
expect(json_response['header_logo']).to eq("/uploads/-/system/appearance/header_logo/#{appearance.id}/dk.png")
expect(json_response['favicon']).to eq("/uploads/-/system/appearance/favicon/#{appearance.id}/dk.png")
end
context "fails on invalid color images" do
it "with string instead of file" do
put api("/application/appearance", admin), params: { logo: 'not-a-file.png' }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq("logo is invalid")
end
it "with .svg file instead of .png" do
put api("/application/appearance", admin), params: { favicon: fixture_file_upload("spec/fixtures/logo_sample.svg", "image/svg") }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['favicon']).to contain_exactly("You are not allowed to upload \"svg\" files, allowed types: png, ico")
end
end
end
end
end
end
|