Merge pull request #7 from psyreactor/develop

Add permission api
This commit is contained in:
Psyreactor 2020-09-03 20:32:54 -03:00 committed by GitHub
commit 62d9fb1dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 725 additions and 2 deletions

View File

@ -30,6 +30,12 @@ jobs:
gem install bundler --no-document
bundle install --jobs 4 --retry 3
bundle exec rake
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lint:
runs-on: ubuntu-latest
name: Rubocop lint

View File

@ -6,6 +6,8 @@ require: rubocop-performance
AllCops:
TargetRubyVersion: 2.5
NewCops: enable
Exclude:
- 'test.rb'
Layout/LineLength:
Max: 123
@ -41,4 +43,4 @@ Style/OptionalBooleanParameter:
Enabled: false
Lint/MissingSuper:
Enabled: false
Enabled: false

View File

@ -5,6 +5,15 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in sonarqube.gemspec
gemspec
group :development do
gem 'guard'
gem 'guard-bundler', require: false
gem 'guard-rspec', require: false
gem 'guard-rubocop'
end
gem 'pry'
gem 'rubocop'
gem 'rubocop-performance'
gem 'simplecov'
gem 'simplecov-lcov'

25
Guardfile Normal file
View File

@ -0,0 +1,25 @@
# frozen_string_literal: true
guard :rspec, cmd: 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end
guard :rubocop do
ignore(/{^test.rb}/)
watch(/{.+\.rb$}/)
watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
end
guard :bundler do
require 'guard/bundler'
require 'guard/bundler/verify'
helper = Guard::Bundler::Verify.new
files = ['Gemfile']
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
# Assume files are symlinked from somewhere
files.each { |file| watch(helper.real_path(file)) }
end

View File

@ -2,6 +2,7 @@
[![Build Status](https://img.shields.io/github/workflow/status/psyreactor/sonarqube/CI/master)](https://github.com/psyreactor/sonarqube/actions?query=workflow%3ARuby)
[![Inline docs](https://inch-ci.org/github/psyreactor/sonarqube.svg)](https://inch-ci.org/github/psyreactor/sonarqube)
[![Coverage Status](https://coveralls.io/repos/github/psyreactor/sonarqube/badge.svg)](https://coveralls.io/github/psyreactor/sonarqube)
[![Gem version](https://img.shields.io/gem/v/sonarqube.svg)](https://rubygems.org/gems/sonarqube)
[![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/psyreactor/sonarqube/blob/master/LICENSE.txt)

View File

@ -0,0 +1,197 @@
---
layout: default
title: Permissions
nav_order: 5
parent: Client
---
<details close markdown="block">
<summary>
Table of contents
</summary>
{: .text-delta }
1. TOC
{:toc}
</details>
# Permissions
## Add Permisssion to group
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = Sonarqube.permissions_add_group({groupName: 'New-Group', permission: permission, projectKey: 'test'})
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
## Add group to template
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = Sonarqube.add_group_to_template({groupName: 'New-Group', permission: permission, templateName: 'test'})
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
## Add project creator to template
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = Sonarqube.add_project_creator_to_template(permission, { templateName: 'test' })
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
## Add permissions to user
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = permission_add_user('user', permission, { templateName: 'test' })
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
## Add user to template
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = Sonarqube.add_user_to_template({ login: 'new_user', permission: 'user', templateName: 'test' })
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
## Apply Template
```ruby
status = Sonarqube.apply_template({ projectName: 'New-Group', templateName: 'test' })
status.to_hash.nil?
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
## Bulk apply template
```ruby
status = Sonarqube.bulk_apply_template({ templateName: 'test', projects: 'my_project,another_project' })
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
status.to_hash.nil?
```
## Create Template
```ruby
status = Sonarqube.create_template('template_name', 'description', '.*\.finance\..*')
# => #<Sonarqube::ObjectifiedHash:46120 {hash: {"permissionTemplate"=>{"id"=>"AXQt1hhmsmLGhox2KqqJ", "name"=>"template_name", "description"=>"description", "projectKeyPattern"=>".*\\.finance\\..*", "createdAt"=>"2020-08-27T02:53:59+0000", "updatedAt"=>"2020-08-27T02:53:59+0000", "permissions"=>[]}}}
status.permissionTemplate.name
# => template_name
```
## Delete Template
```ruby
status = Sonarqube.delete_template({ templateName: 'template_name' })
# => #<Sonarqube::ObjectifiedHash:46120 {hash: {"permissionTemplate"=>{"id"=>"AXQt1hhmsmLGhox2KqqJ", "name"=>"template_name", "description"=>"description", "projectKeyPattern"=>".*\\.finance\\..*", "createdAt"=>"2020-08-27T02:53:59+0000", "updatedAt"=>"2020-08-27T02:53:59+0000", "permissions"=>[]}}}
status.to_hash.nil?
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
```
## Remove group from template
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = Sonarqube.remove_group_from_template({groupName: 'New-Group', permission: permission, templateName: 'test'})
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
## Remove Permission from group
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = Sonarqube.permissions_remove_group({groupName: 'New-Group', permission: permission, projectKey: 'test'})
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```
# Internal Apis
* Use at your own risk; internal services are subject to change or removal without notice (Sonarqube info).
## api/permissions/groups
```ruby
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
status = Sonarqube.permissions_add_group({groupName: 'New-Group', permission: permission, projectKey: 'test'})
status.to_hash.nil?
end
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
# => true
```

View File

@ -10,6 +10,7 @@ nav_order: 1
[![Build Status](https://img.shields.io/github/workflow/status/psyreactor/sonarqube/CI/master)](https://github.com/psyreactor/sonarqube/actions?query=workflow%3ARuby)
[![Inline docs](https://inch-ci.org/github/psyreactor/sonarqube.svg)](https://inch-ci.org/github/psyreactor/sonarqube)
[![Coverage Status](https://coveralls.io/repos/github/psyreactor/sonarqube/badge.svg)](https://coveralls.io/github/psyreactor/sonarqube)
[![Gem version](https://img.shields.io/gem/v/sonarqube.svg)](https://rubygems.org/gems/sonarqube)
[![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/psyreactor/sonarqube/blob/master/LICENSE.txt)

View File

@ -7,6 +7,7 @@ module Sonarqube
# Please keep in alphabetical order
include Groups
include Permissions
include Projects
include Tokens
include Users

View File

@ -0,0 +1,237 @@
# frozen_string_literal: true
class Sonarqube::Client
# Defines methods related to permissions.
# @see https://SONAR_URL/web_api/api/permissions
module Permissions
# Add permission to a group.
#
# @example
# Sonarqube.permissions_add_group({ groupName: 'New-Group', permission: 'user', projectKey: 'test' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :groupId Id of group.
# @option options [String] :groupName Name of group.
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
# @option options [String] :projectId Id of project, only apply for project permissions.
# @option options [String] :projectKey Key of project, only apply for project permissions.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_group}
# @return [<Sonarqube::ObjectifiedHash>]
def permission_add_group(options = {})
options.transform_keys(&:to_sym)
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
post('/api/permissions/add_group', body: options)
end
alias add_group_permission permission_add_group
# Add group to template.
#
# @example
# Sonarqube.add_group_to_template({ groupName: 'New-Group', permission: 'user', templateName: 'test' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :groupId Id of group.
# @option options [String] :groupName Name of group.
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
# @option options [String] :templateId Id of template.
# @option options [String] :templateName Name of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_group_to_template}
# @return [<Sonarqube::ObjectifiedHash>]
def add_group_to_template(options = {})
options.transform_keys(&:to_sym)
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
post('/api/permissions/add_group_to_template', body: options)
end
# Add project creator to template.
#
# @example
# Sonarqube.add_project_creator_to_template('issueadmin', { templateName: 'test' })
#
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
# @param [Hash] options A customizable set of options.
# @option options [String] :templateId Id of template.
# @option options [String] :templateName Name of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_project_creator_to_template}
# @return [<Sonarqube::ObjectifiedHash>]
def add_project_creator_to_template(permission, options = {})
raise ArgumentError, 'Missing required parameters' if permission.nil?
post('/api/permissions/add_project_creator_to_template', body: { permission: permission }.merge!(options))
end
# Add permissions to user.
#
# @example
# Sonarqube.permission_add_user('new_user', 'issueadmin', { projectKey: 'test' })
#
# @param [String] :login Name of login user.
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
# @param [Hash] options A customizable set of options.
# @option options [String] :projectId Id of project, only apply for project permissions.
# @option options [String] :projectKey Key of project, only apply for project permissions.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_user}
# @return [<Sonarqube::ObjectifiedHash>]
def permission_add_user(login, permission, options = {})
options.transform_keys(&:to_sym)
raise ArgumentError, 'Missing required parameters' if login.nil? && permission.nil?
body = { login: login, permission: permission }.merge!(options)
post('/api/permissions/add_user', body: body)
end
alias add_user_permission permission_add_user
# Add user to template.
#
# @example
# Sonarqube.add_user_to_template({ 'new_user', 'issueadmin', { templateName: 'test' })
#
# @param [String] :login Name of login user.
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user.
# @param [Hash] options A customizable set of options.
# @option options [String] :templateId Id of template.
# @option options [String] :templateName Name of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_user_to_template}
# @return [<Sonarqube::ObjectifiedHash>]
def add_user_to_template(login, permission, options = {})
options.transform_keys(&:to_sym)
raise ArgumentError, 'Missing required parameters' if login.nil? && permission.nil?
body = { login: login, permission: permission }.merge!(options)
post('/api/permissions/add_user_to_template', body: body)
end
# Apply template.
#
# @example
# Sonarqube.apply_template({ projectName: 'New-Group', templateName: 'test' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :projectId Id of group.
# @option options [String] :projectName Name of group.
# @option options [String] :templateId Id of template.
# @option options [String] :templateName Name of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/apply_template}
# @return [<Sonarqube::ObjectifiedHash>]
def apply_template(options = {})
options.transform_keys(&:to_sym)
post('/api/permissions/apply_template', body: options)
end
# Bulk apply template.
#
# @example
# Sonarqube.bulk_apply_template({ templateName: 'test', projects: 'my_project,another_project' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :analyzedBefore Filter the projects for which last analysis is older than the given date .
# @option options [String] :onProvisionedOnly Filter the projects that are provisioned.
# @option options [String] :projects Comma-separated list of project keys maximum 1000
# @option options [String] :q serach project names that contain the supplied string and project keys that are exactly the same as the supplied string
# @option options [String] :qualifiers Comma-separated list of component qualifiers. Filter the results with the specified qualifiers.
# @option options [String] :templateId Id of template.
# @option options [String] :templateName Name of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/bulk_apply_template}
# @return [<Sonarqube::ObjectifiedHash>]
def bulk_apply_template(options = {})
options.transform_keys(&:to_sym)
post('/api/permissions/bulk_apply_template', body: options)
end
# Create template.
#
# @example
# Sonarqube.create_template('template_name', 'description', '.*\.finance\..*')
#
# @param [String] :name Name of template.
# @param [String] :project_key_pattern Project key pattern. Must be a valid Java regular expression.
# @param [String] :description Description of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/create_template}
# @return [<Sonarqube::ObjectifiedHash>]
def create_template(name, description, project_key_pattern)
body = { name: name, description: description, projectKeyPattern: project_key_pattern }
post('/api/permissions/create_template', body: body)
end
# Delete template.
#
# @example
# Sonarqube.create_template({ templateName: 'template_name' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :templateId Id of template.
# @option options [String] :templateName Name of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/delete_template}
# @return [<Sonarqube::ObjectifiedHash>]
def delete_template(options = {})
options.transform_keys(&:to_sym)
raise ArgumentError, 'Missing required parameters' if options[:templateName].nil? && options[:templateId].nil?
post('/api/permissions/delete_template', body: options)
end
# Remove permission to a group.
#
# @example
# Sonarqube.permissions_add_group({ groupName: 'New-Group', permission: permission, projectKey: 'test' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :groupId Id of group.
# @option options [String] :groupName Name of group.
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
# @option options [String] :projectId Id of project, only apply for project permissions.
# @option options [String] :projectKey Key of project, only apply for project permissions.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/remove_group}
# @return [<Sonarqube::ObjectifiedHash>]
def permission_remove_group(options = {})
options.transform_keys(&:to_sym)
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
post('/api/permissions/remove_group', body: options)
end
alias remove_group_permission permission_remove_group
# Remove group from template.
#
# @example
# Sonarqube.remove_group_from_template({ groupName: 'New-Group', permission: 'permission', templateId: 'test' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :groupId Id of group.
# @option options [String] :groupName Name of group.
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
# @option options [String] :TemplateId Id of template.
# @option options [String] :TemplateName Name of template.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/remove_group_from_template}
# @return [<Sonarqube::ObjectifiedHash>]
def remove_group_from_template(options = {})
post('/api/permissions/remove_group_from_template', body: options)
end
# Lists the groups with their permissions
#
# @example
# Sonarqube.permission_list_group({ q: 'test', projectsKey: 'project' })
#
# @param [Hash] options A customizable set of options.
# @option options [String] :organization Key of organization, used when group name is set
# @option options [String] :p 1-based page number.
# @option options [String] :permission Possible values for global permissions or values for project permissions.
# @option options [String] :q Limit search to group names that contain the supplied string.
# @option options [String] :ps Page size. Must be greater than 0 and less or equal than 100
# @option options [String] :projectId Id of project.
# @option options [String] :projectKey Key of project.
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/groups?internal=true}
# @return [<Sonarqube::ObjectifiedHash>]
def permission_list_group(options = {})
options.transform_keys(&:to_sym)
get('/api/permissions/groups', quey: options)
end
alias list_group_permission permission_list_group
end
end

1
spec/fixtures/apply_template.json vendored Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{}

1
spec/fixtures/create_template.json vendored Normal file
View File

@ -0,0 +1 @@
{"permissionTemplate": {"name": "template_name","description": "description","projectKeyPattern": ".*\\.finance\\..*"}}

1
spec/fixtures/delete_template.json vendored Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{"paging":{"pageIndex":1,"pageSize":20,"total":5},"groups":[{"id":"Anyone","name":"Anyone","permissions":["provisioning","scan"]},{"id":"AXOt93S3gMZPhbn-E_O6","name":"sonar-administrators","description":"System administrators","permissions":["admin","applicationcreator","gateadmin","portfoliocreator","profileadmin","provisioning"]},{"id":"AXQYrrgCsrvdoo0YodNM","name":"New-Group","description":"Sonarqube group users","permissions":[]},{"id":"AXQRcKrW9pRiZzanEJ2E","name":"Sonarqube-Group","description":"Sonarqube group users","permissions":[]},{"id":"AXOt93S3gMZPhbn-E_O7","name":"sonar-users","description":"Any new users created will automatically join this group","permissions":[]}]}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{}

1
spec/fixtures/template_add_group.json vendored Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{}

1
spec/fixtures/template_add_user.json vendored Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,220 @@
# frozen_string_literal: true
require 'spec_helper'
describe Sonarqube::Client do
describe '.permission_add_group' do
context 'when successful request' do
before do
stub_post('/api/permissions/add_group', 'permission_add_group')
@permission = Sonarqube.permission_add_group({ groupName: 'New-Group', permission: 'user', projectKey: 'test' })
end
it 'gets the correct resource' do
body = { groupName: 'New-Group', permission: 'user', projectKey: 'test' }
expect(a_post('/api/permissions/add_group').with(body: body)).to have_been_made
end
it 'returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.add_group_to_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/add_group_to_template', 'template_add_group')
@permission = Sonarqube.add_group_to_template({ groupName: 'New-Group', permission: 'user', templateName: 'test' })
end
it 'gets the correct resource' do
body = { groupName: 'New-Group', permission: 'user', templateName: 'test' }
expect(a_post('/api/permissions/add_group_to_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.add_project_creator_to_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/add_project_creator_to_template', 'template_add_project_creator')
@permission = Sonarqube.add_project_creator_to_template('user', { templateName: 'test' })
end
it 'gets the correct resource' do
body = { permission: 'user', templateName: 'test' }
expect(a_post('/api/permissions/add_project_creator_to_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.permission_add_user' do
context 'when successful request' do
before do
stub_post('/api/permissions/add_user', 'permission_add_user')
@permission = Sonarqube.permission_add_user('user', 'user', { templateName: 'test' })
end
it 'gets the correct resource' do
body = { login: 'user', permission: 'user', templateName: 'test' }
expect(a_post('/api/permissions/add_user').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.add_user_to_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/add_user_to_template', 'template_add_user')
@permission = Sonarqube.add_user_to_template('new_user', 'user', { templateName: 'test' })
end
it 'gets the correct resource' do
body = { login: 'new_user', permission: 'user', templateName: 'test' }
expect(a_post('/api/permissions/add_user_to_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.apply_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/apply_template', 'apply_template')
@permission = Sonarqube.apply_template({ projectName: 'test', templateName: 'test' })
end
it 'gets the correct resource' do
body = { projectName: 'test', templateName: 'test' }
expect(a_post('/api/permissions/apply_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.bulk_apply_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/bulk_apply_template', 'bulk_apply_template')
@permission = Sonarqube.bulk_apply_template({ projectName: 'test', templateName: 'test' })
end
it 'gets the correct resource' do
body = { projectName: 'test', templateName: 'test' }
expect(a_post('/api/permissions/bulk_apply_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.create_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/create_template', 'create_template')
@permission = Sonarqube.create_template('template_name', 'description', '.*\.finance\..*')
end
it 'gets the correct resource' do
body = { name: 'template_name', description: 'description', projectKeyPattern: '.*\.finance\..*' }
expect(a_post('/api/permissions/create_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.permissionTemplate.name).to eq('template_name')
end
end
end
describe '.delete_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/delete_template', 'delete_template')
@permission = Sonarqube.delete_template({ templateName: 'template_name' })
end
it 'gets the correct resource' do
body = { templateName: 'template_name' }
expect(a_post('/api/permissions/delete_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.permission_remove_group' do
context 'when successful request' do
before do
stub_post('/api/permissions/remove_group', 'permission_remove_group')
@permission = Sonarqube.permission_remove_group({ groupName: 'New-Group', permission: 'user', projectKey: 'test' })
end
it 'gets the correct resource' do
body = { groupName: 'New-Group', permission: 'user', projectKey: 'test' }
expect(a_post('/api/permissions/remove_group').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.remove_group_from_template' do
context 'when successful request' do
before do
stub_post('/api/permissions/remove_group_from_template', 'remove_group_from_template')
@permission = Sonarqube.remove_group_from_template({ groupName: 'New-Group', permission: 'permission', templateName: 'test' })
end
it 'gets the correct resource' do
body = { groupName: 'New-Group', permission: 'permission', templateName: 'test' }
expect(a_post('/api/permissions/remove_group_from_template').with(body: body)).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.to_hash).to be_empty
end
end
end
describe '.permission_list_group' do
context 'when successful request' do
before do
stub_get('/api/permissions/groups', 'permission_list_group')
@permission = Sonarqube.permission_list_group
end
it 'gets the correct resource' do
expect(a_get('/api/permissions/groups')).to have_been_made
end
it 'returns returns empty hash' do
expect(@permission.groups.first.id).to eq('Anyone')
end
end
end
end

View File

@ -30,7 +30,7 @@ describe Sonarqube do
actions = described_class.actions
expect(actions).to be_an Array
expect(actions.first).to be_a Symbol
expect(actions.min).to eq(:add_member)
expect(actions.min).to eq(:add_group_permission)
end
end

View File

@ -2,6 +2,17 @@
require 'rspec'
require 'webmock/rspec'
require 'simplecov'
require 'simplecov-lcov'
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
SimpleCov::Formatter::LcovFormatter.config do |c|
c.output_directory = 'coverage'
c.lcov_file_name = 'lcov.info'
c.single_report_path = 'coverage/lcov.info'
end
SimpleCov.start
require File.expand_path('../lib/sonarqube', __dir__)