summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--app/assets/javascripts/dispatcher.js.coffee7
-rw-r--r--app/controllers/admin/hooks_controller.rb2
-rw-r--r--app/models/hooks/service_hook.rb4
-rw-r--r--app/models/hooks/web_hook.rb16
-rw-r--r--app/models/project.rb2
-rw-r--r--app/services/system_hooks_service.rb6
-rw-r--r--app/services/test_hook_service.rb2
-rw-r--r--app/views/projects/_aside.html.haml4
-rw-r--r--app/views/shared/_clone_panel.html.haml2
-rw-r--r--app/views/shared/_issuable_filter.html.haml2
-rw-r--r--app/workers/project_web_hook_worker.rb4
-rw-r--r--app/workers/system_hook_worker.rb4
-rw-r--r--db/migrate/20150425164647_remove_duplicate_tags.rb3
-rw-r--r--doc/markdown/markdown.md2
-rw-r--r--doc/raketasks/backup_restore.md74
-rw-r--r--doc/security/README.md1
-rw-r--r--doc/security/reset_root_password.md40
-rw-r--r--doc/system_hooks/system_hooks.md6
-rw-r--r--doc/web_hooks/web_hooks.md25
-rw-r--r--lib/api/system_hooks.rb2
-rw-r--r--lib/gitlab/markdown/sanitization_filter.rb19
-rw-r--r--spec/features/markdown_spec.rb28
-rw-r--r--spec/fixtures/markdown.md.erb26
-rw-r--r--spec/lib/gitlab/markdown/sanitization_filter_spec.rb20
-rw-r--r--spec/models/hooks/service_hook_spec.rb33
-rw-r--r--spec/models/hooks/system_hook_spec.rb42
-rw-r--r--spec/models/hooks/web_hook_spec.rb14
28 files changed, 312 insertions, 79 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 33f1344860a..57567728b49 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -24,6 +24,7 @@ v 7.11.0 (unreleased)
- Fix bug causing `@whatever` inside an inline code snippet (backtick-style) to be picked up as a user mention.
- When use change branches link at MR form - save source branch selection instead of target one
- Improve handling of large diffs
+ - Added GitLab Event header for project hooks
-
- Show Atom feed buttons everywhere where applicable.
- Add project activity atom feed.
diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee
index 06787ddf874..2baaf430d98 100644
--- a/app/assets/javascripts/dispatcher.js.coffee
+++ b/app/assets/javascripts/dispatcher.js.coffee
@@ -112,6 +112,13 @@ class Dispatcher
new NamespaceSelect()
when 'dashboard'
shortcut_handler = new ShortcutsDashboardNavigation()
+ switch path[1]
+ when 'issues', 'merge_requests'
+ new UsersSelect()
+ when 'groups'
+ switch path[1]
+ when 'issues', 'merge_requests'
+ new UsersSelect()
when 'profiles'
new Profile()
when 'projects'
diff --git a/app/controllers/admin/hooks_controller.rb b/app/controllers/admin/hooks_controller.rb
index 0a463239d74..690096bdbcf 100644
--- a/app/controllers/admin/hooks_controller.rb
+++ b/app/controllers/admin/hooks_controller.rb
@@ -33,7 +33,7 @@ class Admin::HooksController < Admin::ApplicationController
owner_name: "Someone",
owner_email: "example@gitlabhq.com"
}
- @hook.execute(data)
+ @hook.execute(data, 'system_hooks')
redirect_to :back
end
diff --git a/app/models/hooks/service_hook.rb b/app/models/hooks/service_hook.rb
index 2e11239c40b..5b38ade2e6b 100644
--- a/app/models/hooks/service_hook.rb
+++ b/app/models/hooks/service_hook.rb
@@ -17,4 +17,8 @@
class ServiceHook < WebHook
belongs_to :service
+
+ def execute(data)
+ super(data, 'service_hook')
+ end
end
diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb
index 315d96af1b9..e9fd441352d 100644
--- a/app/models/hooks/web_hook.rb
+++ b/app/models/hooks/web_hook.rb
@@ -30,12 +30,15 @@ class WebHook < ActiveRecord::Base
validates :url, presence: true,
format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" }
- def execute(data)
+ def execute(data, hook_name)
parsed_url = URI.parse(url)
if parsed_url.userinfo.blank?
WebHook.post(url,
body: data.to_json,
- headers: { "Content-Type" => "application/json" },
+ headers: {
+ "Content-Type" => "application/json",
+ "X-Gitlab-Event" => hook_name.singularize.titleize
+ },
verify: false)
else
post_url = url.gsub("#{parsed_url.userinfo}@", "")
@@ -45,7 +48,10 @@ class WebHook < ActiveRecord::Base
}
WebHook.post(post_url,
body: data.to_json,
- headers: { "Content-Type" => "application/json" },
+ headers: {
+ "Content-Type" => "application/json",
+ "X-Gitlab-Event" => hook_name.singularize.titleize
+ },
verify: false,
basic_auth: auth)
end
@@ -54,7 +60,7 @@ class WebHook < ActiveRecord::Base
false
end
- def async_execute(data)
- Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data)
+ def async_execute(data, hook_name)
+ Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data, hook_name)
end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index e866681aab9..bc77e7217ee 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -483,7 +483,7 @@ class Project < ActiveRecord::Base
def execute_hooks(data, hooks_scope = :push_hooks)
hooks.send(hooks_scope).each do |hook|
- hook.async_execute(data)
+ hook.async_execute(data, hooks_scope.to_s)
end
end
diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb
index c5d0b08845b..60235b6be2a 100644
--- a/app/services/system_hooks_service.rb
+++ b/app/services/system_hooks_service.rb
@@ -7,12 +7,12 @@ class SystemHooksService
def execute_hooks(data)
SystemHook.all.each do |sh|
- async_execute_hook sh, data
+ async_execute_hook(sh, data, 'system_hooks')
end
end
- def async_execute_hook(hook, data)
- Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data)
+ def async_execute_hook(hook, data, hook_name)
+ Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data, hook_name)
end
def build_event_data(model, event)
diff --git a/app/services/test_hook_service.rb b/app/services/test_hook_service.rb
index 21ec2c01cb8..e85e58751e7 100644
--- a/app/services/test_hook_service.rb
+++ b/app/services/test_hook_service.rb
@@ -1,6 +1,6 @@
class TestHookService
def execute(hook, current_user)
data = Gitlab::PushDataBuilder.build_sample(hook.project, current_user)
- hook.execute(data)
+ hook.execute(data, 'push_hooks')
end
end
diff --git a/app/views/projects/_aside.html.haml b/app/views/projects/_aside.html.haml
index 1865b5be8c6..1241b51f9ac 100644
--- a/app/views/projects/_aside.html.haml
+++ b/app/views/projects/_aside.html.haml
@@ -4,7 +4,9 @@
- unless @project.empty_repo?
.well
- %h4 Repository
+ %h4.visibility-level-label
+ = visibility_level_icon(@project.visibility_level)
+ = "#{visibility_level_label(@project.visibility_level).capitalize} project"
%ul.nav.nav-pills
%li= link_to pluralize(number_with_delimiter(@repository.commit_count), 'commit'), namespace_project_commits_path(@project.namespace, @project, @ref || @repository.root_ref)
%li= link_to pluralize(number_with_delimiter(@repository.branch_names.count), 'branch'), namespace_project_branches_path(@project.namespace, @project)
diff --git a/app/views/shared/_clone_panel.html.haml b/app/views/shared/_clone_panel.html.haml
index 60bb76e898a..3f489a04e71 100644
--- a/app/views/shared/_clone_panel.html.haml
+++ b/app/views/shared/_clone_panel.html.haml
@@ -18,7 +18,7 @@
:"data-container" => "body"}
= gitlab_config.protocol.upcase
= text_field_tag :project_clone, default_url_to_repo(project), class: "js-select-on-focus form-control input-sm", readonly: true
- - if project.kind_of?(Project)
+ - if project.kind_of?(Project) && project.empty_repo?
.input-group-addon
.visibility-level-label.has_tooltip{'data-title' => "#{visibility_level_label(project.visibility_level)} project" }
= visibility_level_icon(project.visibility_level)
diff --git a/app/views/shared/_issuable_filter.html.haml b/app/views/shared/_issuable_filter.html.haml
index fa8b4eae314..4ab9421f013 100644
--- a/app/views/shared/_issuable_filter.html.haml
+++ b/app/views/shared/_issuable_filter.html.haml
@@ -51,8 +51,6 @@
= button_tag "Update issues", class: "btn update_selected_issues btn-save"
:coffeescript
- new UsersSelect()
-
$('form.filter-form').on 'submit', (event) ->
event.preventDefault()
Turbolinks.visit @.action + '&' + $(@).serialize()
diff --git a/app/workers/project_web_hook_worker.rb b/app/workers/project_web_hook_worker.rb
index 73085c046bd..fb878965288 100644
--- a/app/workers/project_web_hook_worker.rb
+++ b/app/workers/project_web_hook_worker.rb
@@ -3,8 +3,8 @@ class ProjectWebHookWorker
sidekiq_options queue: :project_web_hook
- def perform(hook_id, data)
+ def perform(hook_id, data, hook_name)
data = data.with_indifferent_access
- WebHook.find(hook_id).execute(data)
+ WebHook.find(hook_id).execute(data, hook_name)
end
end
diff --git a/app/workers/system_hook_worker.rb b/app/workers/system_hook_worker.rb
index 3ebc62b7e7a..a122c274763 100644
--- a/app/workers/system_hook_worker.rb
+++ b/app/workers/system_hook_worker.rb
@@ -3,7 +3,7 @@ class SystemHookWorker
sidekiq_options queue: :system_hook
- def perform(hook_id, data)
- SystemHook.find(hook_id).execute data
+ def perform(hook_id, data, hook_name)
+ SystemHook.find(hook_id).execute(data, hook_name)
end
end
diff --git a/db/migrate/20150425164647_remove_duplicate_tags.rb b/db/migrate/20150425164647_remove_duplicate_tags.rb
index 1a9152cb965..13e5038db9c 100644
--- a/db/migrate/20150425164647_remove_duplicate_tags.rb
+++ b/db/migrate/20150425164647_remove_duplicate_tags.rb
@@ -1,7 +1,8 @@
class RemoveDuplicateTags < ActiveRecord::Migration
def up
select_all("SELECT name, COUNT(id) as cnt FROM tags GROUP BY name HAVING COUNT(id) > 1").each do |tag|
- duplicate_ids = select_all("SELECT id FROM tags WHERE name = '#{tag["name"]}'").map{|tag| tag["id"]}
+ tag_name = quote_string(tag["name"])
+ duplicate_ids = select_all("SELECT id FROM tags WHERE name = '#{tag_name}'").map{|tag| tag["id"]}
origin_tag_id = duplicate_ids.first
duplicate_ids.delete origin_tag_id
diff --git a/doc/markdown/markdown.md b/doc/markdown/markdown.md
index e95ddbb7578..30c29084e34 100644
--- a/doc/markdown/markdown.md
+++ b/doc/markdown/markdown.md
@@ -423,7 +423,7 @@ Quote break.
You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
-See the documentation for HTML::Pipeline's [SanitizationFilter](http://www.rubydoc.info/gems/html-pipeline/HTML/Pipeline/SanitizationFilter#WHITELIST-constant) class for the list of allowed HTML tags and attributes. In addition to the default `SanitizationFilter` whitelist, GitLab allows `span` elements, as well as the `class`, and `id` attributes on all elements.
+See the documentation for HTML::Pipeline's [SanitizationFilter](http://www.rubydoc.info/gems/html-pipeline/HTML/Pipeline/SanitizationFilter#WHITELIST-constant) class for the list of allowed HTML tags and attributes. In addition to the default `SanitizationFilter` whitelist, GitLab allows `span` elements.
```no-highlight
<dl>
diff --git a/doc/raketasks/backup_restore.md b/doc/raketasks/backup_restore.md
index bfef975024f..bca4fcfb404 100644
--- a/doc/raketasks/backup_restore.md
+++ b/doc/raketasks/backup_restore.md
@@ -9,6 +9,8 @@ This archive will be saved in backup_path (see `config/gitlab.yml`).
The filename will be `[TIMESTAMP]_gitlab_backup.tar`. This timestamp can be used to restore an specific backup.
You can only restore a backup to exactly the same version of GitLab that you created it on, for example 7.2.1.
+If you are interested in GitLab CI backup please follow to the [CI backup documentation](https://gitlab.com/gitlab-org/gitlab-ci/blob/master/doc/raketasks/backup_restore.md)*
+
```
# use this command if you've installed GitLab with the Omnibus package
sudo gitlab-rake gitlab:backup:create
@@ -150,11 +152,9 @@ If you have an installation from source, please consider backing up your `gitlab
You can only restore a backup to exactly the same version of GitLab that you created it on, for example 7.2.1.
-```
-# Omnibus package installation
-sudo gitlab-rake gitlab:backup:restore
+### Installation from source
-# installation from source
+```
bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
@@ -196,11 +196,45 @@ Restoring repositories:
Deleting tmp directories...[DONE]
```
-## Configure cron to make daily backups
+### Omnibus installations
+
+We will assume that you have installed GitLab from an omnibus package and run
+`sudo gitlab-ctl reconfigure` at least once.
+
+First make sure your backup tar file is in `/var/opt/gitlab/backups`.
+
+```shell
+sudo cp 1393513186_gitlab_backup.tar /var/opt/gitlab/backups/
+```
-For Omnibus package installations, see https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#scheduling-a-backup .
+Next, restore the backup by running the restore command. You need to specify the
+timestamp of the backup you are restoring.
-For installation from source:
+```shell
+# Stop processes that are connected to the database
+sudo gitlab-ctl stop unicorn
+sudo gitlab-ctl stop sidekiq
+
+# This command will overwrite the contents of your GitLab database!
+sudo gitlab-rake gitlab:backup:restore BACKUP=1393513186
+
+# Start GitLab
+sudo gitlab-ctl start
+
+# Create satellites
+sudo gitlab-rake gitlab:satellites:create
+
+# Check GitLab
+sudo gitlab-rake gitlab:check SANITIZE=true
+```
+
+If there is a GitLab version mismatch between your backup tar file and the installed
+version of GitLab, the restore command will abort with an error. Install a package for
+the [required version](https://www.gitlab.com/downloads/archives/) and try again.
+
+## Configure cron to make daily backups
+
+### For installation from source:
```
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml # Enable keep_time in the backup section to automatically delete old backups
@@ -217,6 +251,32 @@ Add the following lines at the bottom:
The `CRON=1` environment setting tells the backup script to suppress all progress output if there are no errors.
This is recommended to reduce cron spam.
+### For omnibus installations
+
+To schedule a cron job that backs up your repositories and GitLab metadata, use the root user:
+
+```
+sudo su -
+crontab -e
+```
+
+There, add the following line to schedule the backup for everyday at 2 AM:
+
+```
+0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
+```
+
+You may also want to set a limited lifetime for backups to prevent regular
+backups using all your disk space. To do this add the following lines to
+`/etc/gitlab/gitlab.rb` and reconfigure:
+
+```
+# limit backup lifetime to 7 days - 604800 seconds
+gitlab_rails['backup_keep_time'] = 604800
+```
+
+NOTE: This cron job does not [backup your omnibus-gitlab configuration](#backup-and-restore-omnibus-gitlab-configuration) or [SSH host keys](https://superuser.com/questions/532040/copy-ssh-keys-from-one-server-to-another-server/532079#532079).
+
## Alternative backup strategies
If your GitLab server contains a lot of Git repository data you may find the GitLab backup script to be too slow.
diff --git a/doc/security/README.md b/doc/security/README.md
index 49dfa6eec76..473f3632dcd 100644
--- a/doc/security/README.md
+++ b/doc/security/README.md
@@ -4,3 +4,4 @@
- [Rack attack](rack_attack.md)
- [Web Hooks and insecure internal web services](webhooks.md)
- [Information exclusivity](information_exclusivity.md)
+- [Reset your root password](reset_root_password.md) \ No newline at end of file
diff --git a/doc/security/reset_root_password.md b/doc/security/reset_root_password.md
new file mode 100644
index 00000000000..3c13f262677
--- /dev/null
+++ b/doc/security/reset_root_password.md
@@ -0,0 +1,40 @@
+# How to reset your root password
+
+Log into your server with root privileges. Then start a Ruby on Rails console.
+
+Start the console with this command:
+
+```bash
+gitlab-rails console production
+```
+
+Wait until the console has loaded.
+
+There are multiple ways to find your user. You can search for email or username.
+
+```bash
+user = User.where(id: 1).first
+```
+
+or
+
+```bash
+user = User.find_by(email: 'admin@local.host')
+```
+
+Now you can change your password:
+
+```bash
+user.password = 'secret_pass'
+user.password_confirmation = 'secret_pass'
+```
+
+It's important that you change both password and password_confirmation to make it work.
+
+Don't forget to save the changes.
+
+```bash
+user.save!
+```
+
+Exit the console and try to login with your new password. \ No newline at end of file
diff --git a/doc/system_hooks/system_hooks.md b/doc/system_hooks/system_hooks.md
index f9b6d37d840..b0e4613cdef 100644
--- a/doc/system_hooks/system_hooks.md
+++ b/doc/system_hooks/system_hooks.md
@@ -6,6 +6,12 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser
## Hooks request example
+**Request header**:
+
+```
+X-Gitlab-Event: System Hook
+```
+
**Project created:**
```json
diff --git a/doc/web_hooks/web_hooks.md b/doc/web_hooks/web_hooks.md
index 851f50f5e9a..01082555192 100644
--- a/doc/web_hooks/web_hooks.md
+++ b/doc/web_hooks/web_hooks.md
@@ -12,6 +12,12 @@ If you send a web hook to an SSL endpoint [the certificate will not be verified]
Triggered when you push to the repository except when pushing tags.
+**Request header**:
+
+```
+X-Gitlab-Event: Push Hook
+```
+
**Request body:**
```json
@@ -63,6 +69,13 @@ Triggered when you push to the repository except when pushing tags.
Triggered when you create (or delete) tags to the repository.
+**Request header**:
+
+```
+X-Gitlab-Event: Tag Push Hook
+```
+
+
**Request body:**
```json
@@ -92,6 +105,12 @@ Triggered when you create (or delete) tags to the repository.
Triggered when a new issue is created or an existing issue was updated/closed/reopened.
+**Request header**:
+
+```
+X-Gitlab-Event: Issue Hook
+```
+
**Request body:**
```json
@@ -126,6 +145,12 @@ Triggered when a new issue is created or an existing issue was updated/closed/re
Triggered when a new merge request is created or an existing merge request was updated/merged/closed.
+**Request header**:
+
+```
+X-Gitlab-Event: Merge Request Hook
+```
+
**Request body:**
```json
diff --git a/lib/api/system_hooks.rb b/lib/api/system_hooks.rb
index 518964db50d..22b8f90dc5c 100644
--- a/lib/api/system_hooks.rb
+++ b/lib/api/system_hooks.rb
@@ -47,7 +47,7 @@ module API
owner_name: "Someone",
owner_email: "example@gitlabhq.com"
}
- @hook.execute(data)
+ @hook.execute(data, 'system_hooks')
data
end
diff --git a/lib/gitlab/markdown/sanitization_filter.rb b/lib/gitlab/markdown/sanitization_filter.rb
index 9a154e0b2fe..6f33155badf 100644
--- a/lib/gitlab/markdown/sanitization_filter.rb
+++ b/lib/gitlab/markdown/sanitization_filter.rb
@@ -10,8 +10,9 @@ module Gitlab
def whitelist
whitelist = HTML::Pipeline::SanitizationFilter::WHITELIST
- # Allow `class` and `id` on all elements
- whitelist[:attributes][:all].push('class', 'id')
+ # Allow code highlighting
+ whitelist[:attributes]['pre'] = %w(class)
+ whitelist[:attributes]['span'] = %w(class)
# Allow table alignment
whitelist[:attributes]['th'] = %w(style)
@@ -23,6 +24,9 @@ module Gitlab
# Remove `rel` attribute from `a` elements
whitelist[:transformers].push(remove_rel)
+ # Remove `class` attribute from non-highlight spans
+ whitelist[:transformers].push(clean_spans)
+
whitelist
end
@@ -33,6 +37,17 @@ module Gitlab
end
end
end
+
+ def clean_spans
+ lambda do |env|
+ return unless env[:node_name] == 'span'
+ return unless env[:node].has_attribute?('class')
+
+ unless has_ancestor?(env[:node], 'pre')
+ env[:node].remove_attribute('class')
+ end
+ end
+ end
end
end
end
diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb
index 1746ce128e4..8f3dfc8d5a9 100644
--- a/spec/features/markdown_spec.rb
+++ b/spec/features/markdown_spec.rb
@@ -60,8 +60,8 @@ describe 'GitLab Markdown' do
@feat.teardown
end
- # Given a header ID, goes to that element's parent (the header), then to its
- # second sibling (the body).
+ # Given a header ID, goes to that element's parent (the header itself), then
+ # its next sibling element (the body).
def get_section(id)
@doc.at_css("##{id}").parent.next_element
end
@@ -119,18 +119,18 @@ describe 'GitLab Markdown' do
describe 'HTML::Pipeline' do
describe 'SanitizationFilter' do
it 'uses a permissive whitelist' do
- expect(@doc).to have_selector('b#manual-b')
- expect(@doc).to have_selector('em#manual-em')
- expect(@doc).to have_selector("code#manual-code")
+ expect(@doc).to have_selector('b:contains("b tag")')
+ expect(@doc).to have_selector('em:contains("em tag")')
+ expect(@doc).to have_selector('code:contains("code tag")')
expect(@doc).to have_selector('kbd:contains("s")')
expect(@doc).to have_selector('strike:contains(Emoji)')
- expect(@doc).to have_selector('img#manual-img')
- expect(@doc).to have_selector('br#manual-br')
- expect(@doc).to have_selector('hr#manual-hr')
+ expect(@doc).to have_selector('img[src*="smile.png"]')
+ expect(@doc).to have_selector('br')
+ expect(@doc).to have_selector('hr')
end
it 'permits span elements' do
- expect(@doc).to have_selector('span#span-class-light.light')
+ expect(@doc).to have_selector('span:contains("span tag")')
end
it 'permits table alignment' do
@@ -144,13 +144,12 @@ describe 'GitLab Markdown' do
end
it 'removes `rel` attribute from links' do
- expect(@doc).to have_selector('a#a-rel-nofollow')
- expect(@doc).not_to have_selector('a#a-rel-nofollow[rel]')
+ body = get_section('sanitizationfilter')
+ expect(body).not_to have_selector('a[rel]')
end
it "removes `href` from `a` elements if it's fishy" do
- expect(@doc).to have_selector('a#a-href-javascript')
- expect(@doc).not_to have_selector('a#a-href-javascript[href]')
+ expect(@doc).not_to have_selector('a[href*="javascript"]')
end
end
@@ -228,7 +227,8 @@ describe 'GitLab Markdown' do
%w(code a kbd).each do |elem|
it "ignores links inside '#{elem}' element" do
- expect(@doc.at_css("#{elem}#autolink-#{elem}").child).to be_text
+ body = get_section('autolinkfilter')
+ expect(body).not_to have_selector("#{elem} a")
end
end
end
diff --git a/spec/fixtures/markdown.md.erb b/spec/fixtures/markdown.md.erb
index bc023ecf793..64817ec6700 100644
--- a/spec/fixtures/markdown.md.erb
+++ b/spec/fixtures/markdown.md.erb
@@ -54,36 +54,34 @@ After the Markdown has been turned into HTML, it gets passed through...
### SanitizationFilter
-GitLab uses <a href="http://git.io/vfW8a" class="sanitize" id="sanitize-link">HTML::Pipeline::SanitizationFilter</a>
+GitLab uses <a href="http://git.io/vfW8a">HTML::Pipeline::SanitizationFilter</a>
to sanitize the generated HTML, stripping dangerous or unwanted tags.
Its default whitelist is pretty permissive. Check it:
-<b id="manual-b">This text is bold</b> and <em id="manual-em">this text is emphasized</em>.
+<b>b tag</b> and <em>em tag</em>.
-<code id="manual-code">echo "Hello, world!"</code>
+<code>code tag</code>
Press <kbd>s</kbd> to search.
-<strike>Emoji</strike> Plain old images! <img
-src="http://www.emoji-cheat-sheet.com/graphics/emojis/smile.png" width="20"
-height="20" id="manual-img" />
+<strike>Emoji</strike> Plain old images! <img src="http://www.emoji-cheat-sheet.com/graphics/emojis/smile.png" width="20" height="20" />
Here comes a line break:
-<br id="manual-br" />
+<br />
And a horizontal rule:
-<hr id="manual-hr" />
+<hr />
As permissive as it is, we've allowed even more stuff:
-<span class="light" id="span-class-light">Span elements</span>
+<span>span tag</span>
-<a href="#" rel="nofollow" id="a-rel-nofollow">This is a link with a defined rel attribute, which should be removed</a>
+<a href="#" rel="nofollow">This is a link with a defined rel attribute, which should be removed</a>
-<a href="javascript:alert('Hi')" id="a-href-javascript">This is a link trying to be sneaky. It gets its link removed entirely.</a>
+<a href="javascript:alert('Hi')">This is a link trying to be sneaky. It gets its link removed entirely.</a>
### Escaping
@@ -125,9 +123,9 @@ These are all plain text that should get turned into links:
But it shouldn't autolink text inside certain tags:
-- <code id="autolink-code">http://about.gitlab.com/</code>
-- <a id="autolink-a">http://about.gitlab.com/</a>
-- <kbd id="autolink-kbd">http://about.gitlab.com/</kbd>
+- <code>http://about.gitlab.com/</code>
+- <a>http://about.gitlab.com/</a>
+- <kbd>http://about.gitlab.com/</kbd>
### Reference Filters (e.g., #<%= issue.iid %>)
diff --git a/spec/lib/gitlab/markdown/sanitization_filter_spec.rb b/spec/lib/gitlab/markdown/sanitization_filter_spec.rb
index ab909a68635..4a1aa766149 100644
--- a/spec/lib/gitlab/markdown/sanitization_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/sanitization_filter_spec.rb
@@ -29,17 +29,27 @@ module Gitlab::Markdown
exp = act = "<dl>\n<dt>Term</dt>\n<dd>Definition</dd>\n</dl>"
expect(filter(act).to_html).to eq exp
end
+
+ it 'sanitizes `class` attribute on any element' do
+ act = %q{<strong class="foo">Strong</strong>}
+ expect(filter(act).to_html).to eq %q{<strong>Strong</strong>}
+ end
+
+ it 'sanitizes `id` attribute on any element' do
+ act = %q{<em id="foo">Emphasis</em>}
+ expect(filter(act).to_html).to eq %q{<em>Emphasis</em>}
+ end
end
describe 'custom whitelist' do
- it 'allows `class` attribute on any element' do
- exp = act = %q{<strong class="foo">Strong</strong>}
+ it 'allows syntax highlighting' do
+ exp = act = %q{<pre class="code highlight white c"><code><span class="k">def</span></code></pre>}
expect(filter(act).to_html).to eq exp
end
- it 'allows `id` attribute on any element' do
- exp = act = %q{<em id="foo">Emphasis</em>}
- expect(filter(act).to_html).to eq exp
+ it 'sanitizes `class` attribute from non-highlight spans' do
+ act = %q{<span class="k">def</span>}
+ expect(filter(act).to_html).to eq %q{<span>def</span>}
end
it 'allows `style` attribute on table elements' do
diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb
index 96bf74d45da..d9714596f5d 100644
--- a/spec/models/hooks/service_hook_spec.rb
+++ b/spec/models/hooks/service_hook_spec.rb
@@ -21,4 +21,37 @@ describe ServiceHook do
describe "Associations" do
it { is_expected.to belong_to :service }
end
+
+ describe "execute" do
+ before(:each) do
+ @service_hook = create(:service_hook)
+ @data = { project_id: 1, data: {}}
+
+ WebMock.stub_request(:post, @service_hook.url)
+ end
+
+ it "POSTs to the web hook URL" do
+ @service_hook.execute(@data)
+ expect(WebMock).to have_requested(:post, @service_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Service Hook'}
+ ).once
+ end
+
+ it "POSTs the data as JSON" do
+ json = @data.to_json
+
+ @service_hook.execute(@data)
+ expect(WebMock).to have_requested(:post, @service_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Service Hook'}
+ ).once
+ end
+
+ it "catches exceptions" do
+ expect(WebHook).to receive(:post).and_raise("Some HTTP Post error")
+
+ expect {
+ @service_hook.execute(@data)
+ }.to raise_error
+ end
+ end
end
diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb
index 810b311a40b..e4b6b886565 100644
--- a/spec/models/hooks/system_hook_spec.rb
+++ b/spec/models/hooks/system_hook_spec.rb
@@ -26,32 +26,47 @@ describe SystemHook do
it "project_create hook" do
Projects::CreateService.new(create(:user), name: 'empty').execute
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_create/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /project_create/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "project_destroy hook" do
user = create(:user)
project = create(:empty_project, namespace: user.namespace)
Projects::DestroyService.new(project, user, {}).execute
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /project_destroy/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "user_create hook" do
create(:user)
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_create/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_create/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "user_destroy hook" do
user = create(:user)
user.destroy
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_destroy/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "project_create hook" do
user = create(:user)
project = create(:project)
project.team << [user, :master]
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_add_to_team/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "project_destroy hook" do
@@ -59,13 +74,17 @@ describe SystemHook do
project = create(:project)
project.team << [user, :master]
project.project_members.destroy_all
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_remove_from_team/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it 'group create hook' do
create(:group)
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /group_create/
+ body: /group_create/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
@@ -73,7 +92,8 @@ describe SystemHook do
group = create(:group)
group.destroy
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /group_destroy/
+ body: /group_destroy/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
@@ -82,7 +102,8 @@ describe SystemHook do
user = create(:user)
group.add_user(user, Gitlab::Access::MASTER)
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /user_add_to_group/
+ body: /user_add_to_group/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
@@ -92,7 +113,8 @@ describe SystemHook do
group.add_user(user, Gitlab::Access::MASTER)
group.group_members.destroy_all
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /user_remove_from_group/
+ body: /user_remove_from_group/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb
index 67ec9193ad7..9f5ef3eff70 100644
--- a/spec/models/hooks/web_hook_spec.rb
+++ b/spec/models/hooks/web_hook_spec.rb
@@ -52,22 +52,26 @@ describe ProjectHook do
end
it "POSTs to the web hook URL" do
- @project_hook.execute(@data)
- expect(WebMock).to have_requested(:post, @project_hook.url).once
+ @project_hook.execute(@data, 'push_hooks')
+ expect(WebMock).to have_requested(:post, @project_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Push Hook'}
+ ).once
end
it "POSTs the data as JSON" do
json = @data.to_json
- @project_hook.execute(@data)
- expect(WebMock).to have_requested(:post, @project_hook.url).with(body: json).once
+ @project_hook.execute(@data, 'push_hooks')
+ expect(WebMock).to have_requested(:post, @project_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Push Hook'}
+ ).once
end
it "catches exceptions" do
expect(WebHook).to receive(:post).and_raise("Some HTTP Post error")
expect {
- @project_hook.execute(@data)
+ @project_hook.execute(@data, 'push_hooks')
}.to raise_error
end
end