summaryrefslogtreecommitdiff
path: root/spec/requests/projects_security_spec.rb
blob: a725a49c2d87fc2e3b8fc540bc76c7722b0784fe (plain)
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
require 'spec_helper'

describe "Projects" do
  describe "GET /projects" do 
    it { projects_path.should be_allowed_for :admin }
    it { projects_path.should be_allowed_for :user }
    it { projects_path.should be_denied_for :visitor }
  end

  describe "GET /projects/new" do 
    it { projects_path.should be_allowed_for :admin }
    it { projects_path.should be_allowed_for :user }
    it { projects_path.should be_denied_for :visitor }
  end

  describe "Project" do
    before do 
      @project = Factory :project
      @u1 = Factory :user
      @u2 = Factory :user
      @u3 = Factory :user
      # full access
      @project.users_projects.create(:user => @u1, :read => true, :write => true, :admin => true) 
      # no access
      @project.users_projects.create(:user => @u2, :read => false, :write => false, :admin => false) 
      # readonly
      @project.users_projects.create(:user => @u3, :read => true, :write => false, :admin => false) 
    end

    describe "GET /project_code" do 
      it { project_path(@project).should be_allowed_for @u1 }
      it { project_path(@project).should be_allowed_for @u3 }
      it { project_path(@project).should be_denied_for :admin }
      it { project_path(@project).should be_denied_for @u2 }
      it { project_path(@project).should be_denied_for :user }
      it { project_path(@project).should be_denied_for :visitor }
    end

    describe "GET /project_code/tree" do 
      it { tree_project_path(@project).should be_allowed_for @u1 }
      it { tree_project_path(@project).should be_allowed_for @u3 }
      it { tree_project_path(@project).should be_denied_for :admin }
      it { tree_project_path(@project).should be_denied_for @u2 }
      it { tree_project_path(@project).should be_denied_for :user }
      it { tree_project_path(@project).should be_denied_for :visitor }
    end

    describe "GET /project_code/commits" do 
      it { project_commits_path(@project).should be_allowed_for @u1 }
      it { project_commits_path(@project).should be_allowed_for @u3 }
      it { project_commits_path(@project).should be_denied_for :admin }
      it { project_commits_path(@project).should be_denied_for @u2 }
      it { project_commits_path(@project).should be_denied_for :user }
      it { project_commits_path(@project).should be_denied_for :visitor }
    end

    describe "GET /project_code/commit" do 
      it { project_commit_path(@project, @project.commit).should be_allowed_for @u1 }
      it { project_commit_path(@project, @project.commit).should be_allowed_for @u3 }
      it { project_commit_path(@project, @project.commit).should be_denied_for :admin }
      it { project_commit_path(@project, @project.commit).should be_denied_for @u2 }
      it { project_commit_path(@project, @project.commit).should be_denied_for :user }
      it { project_commit_path(@project, @project.commit).should be_denied_for :visitor }
    end

    describe "GET /project_code/team" do 
      it { team_project_path(@project).should be_allowed_for @u1 }
      it { team_project_path(@project).should be_allowed_for @u3 }
      it { team_project_path(@project).should be_denied_for :admin }
      it { team_project_path(@project).should be_denied_for @u2 }
      it { team_project_path(@project).should be_denied_for :user }
      it { team_project_path(@project).should be_denied_for :visitor }
    end

    describe "GET /project_code/wall" do 
      it { wall_project_path(@project).should be_allowed_for @u1 }
      it { wall_project_path(@project).should be_allowed_for @u3 }
      it { wall_project_path(@project).should be_denied_for :admin }
      it { wall_project_path(@project).should be_denied_for @u2 }
      it { wall_project_path(@project).should be_denied_for :user }
      it { wall_project_path(@project).should be_denied_for :visitor }
    end

    describe "GET /project_code/blob" do 
      it { blob_project_path(@project).should be_allowed_for @u1 }
      it { blob_project_path(@project).should be_allowed_for @u3 }
      it { blob_project_path(@project).should be_denied_for :admin }
      it { blob_project_path(@project).should be_denied_for @u2 }
      it { blob_project_path(@project).should be_denied_for :user }
      it { blob_project_path(@project).should be_denied_for :visitor }
    end

    describe "GET /project_code/edit" do 
      it { edit_project_path(@project).should be_allowed_for @u1 }
      it { edit_project_path(@project).should be_denied_for @u3 }
      it { edit_project_path(@project).should be_denied_for :admin }
      it { edit_project_path(@project).should be_denied_for @u2 }
      it { edit_project_path(@project).should be_denied_for :user }
      it { edit_project_path(@project).should be_denied_for :visitor }
    end

    describe "GET /project_code/issues" do 
      it { project_issues_path(@project).should be_allowed_for @u1 }
      it { project_issues_path(@project).should be_allowed_for @u3 }
      it { project_issues_path(@project).should be_denied_for :admin }
      it { project_issues_path(@project).should be_denied_for @u2 }
      it { project_issues_path(@project).should be_denied_for :user }
      it { project_issues_path(@project).should be_denied_for :visitor }
    end
  end
end