summaryrefslogtreecommitdiff
path: root/spec/routing/routing_spec.rb
blob: 7b9ba7838851c32f37e6ee7b5d85a51bc81ce35c (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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# frozen_string_literal: true

require 'spec_helper'

# user                       GET    /:username
# user_ssh_keys              GET    /:username.keys
# user_gpg_keys              GET    /:username.gpg
# user_groups                GET    /users/:username/groups(.:format)
# user_projects              GET    /users/:username/projects(.:format)
# user_contributed_projects  GET    /users/:username/contributed(.:format)
# user_snippets              GET    /users/:username/snippets(.:format)
# user_calendar              GET    /users/:username/calendar(.:format)
# user_calendar_activities   GET    /users/:username/calendar_activities(.:format)
RSpec.describe UsersController, "routing" do
  it "to #show" do
    allow_any_instance_of(::Constraints::UserUrlConstrainer).to receive(:matches?).and_return(true)

    expect(get("/User")).to route_to('users#show', username: 'User')
  end

  it "to #gpg_keys" do
    allow_any_instance_of(::Constraints::UserUrlConstrainer).to receive(:matches?).and_return(true)

    expect(get("/User.gpg")).to route_to('users#gpg_keys', username: 'User')
  end

  it "to #groups" do
    expect(get("/users/User/groups")).to route_to('users#groups', username: 'User')
  end

  it "to #projects" do
    expect(get("/users/User/projects")).to route_to('users#projects', username: 'User')
  end

  it "to #contributed" do
    expect(get("/users/User/contributed")).to route_to('users#contributed', username: 'User')
  end

  it "to #snippets" do
    expect(get("/users/User/snippets")).to route_to('users#snippets', username: 'User')
  end

  # get all the ssh-keys of a user
  it "to #ssh_keys" do
    allow_any_instance_of(::Constraints::UserUrlConstrainer).to receive(:matches?).and_return(true)

    expect(get("/User.keys")).to route_to('users#ssh_keys', username: 'User')
  end

  it "to #calendar" do
    expect(get("/users/User/calendar")).to route_to('users#calendar', username: 'User')
  end

  it "to #calendar_activities" do
    expect(get("/users/User/calendar_activities")).to route_to('users#calendar_activities', username: 'User')
  end
end

# search GET    /search(.:format) search#show
RSpec.describe SearchController, "routing" do
  it "to #show" do
    expect(get("/search")).to route_to('search#show')
  end
end

# gitlab_api /api         API::API
#            /:path       Grack
RSpec.describe "Mounted Apps", "routing" do
  it "to API" do
    expect(get("/api/issues")).to be_routable
  end
end

#     snippets GET    /snippets(.:format)          snippets#index
#  new_snippet GET    /snippets/new(.:format)      snippets#new
# edit_snippet GET    /snippets/:id/edit(.:format) snippets#edit
#      snippet GET    /snippets/:id(.:format)      snippets#show
RSpec.describe SnippetsController, "routing" do
  it "to #raw" do
    expect(get("/-/snippets/1/raw")).to route_to('snippets#raw', id: '1')
  end

  it "to #index" do
    expect(get("/-/snippets")).to route_to('snippets#index')
  end

  it "to #new" do
    expect(get("/-/snippets/new")).to route_to('snippets#new')
  end

  it "to #edit" do
    expect(get("/-/snippets/1/edit")).to route_to('snippets#edit', id: '1')
  end

  it "to #show" do
    expect(get("/-/snippets/1")).to route_to('snippets#show', id: '1')
  end

  it 'to #show from unscoped routing' do
    expect(get("/snippets/1")).to route_to('snippets#show', id: '1')
  end
end

#            help GET /help(.:format)                 help#index
#       help_page GET /help/*path(.:format)           help#show
#  help_shortcuts GET /help/shortcuts(.:format)       help#shortcuts
RSpec.describe HelpController, "routing" do
  it "to #index" do
    expect(get("/help")).to route_to('help#index')
  end

  it 'to #show' do
    path = '/help/user/markdown.md'
    expect(get(path)).to route_to('help#show',
                                  path: 'user/markdown',
                                  format: 'md')

    path = '/help/user/markdown/markdown_logo.png'
    expect(get(path)).to route_to('help#show',
                                  path: 'user/markdown/markdown_logo',
                                  format: 'png')
  end
end

#             profile_account GET    /-/profile/account(.:format)             profile#account
#             profile_history GET    /-/profile/history(.:format)             profile#history
#            profile_password PUT    /-/profile/password(.:format)            profile#password_update
#               profile_token GET    /-/profile/token(.:format)               profile#token
#                     profile GET    /-/profile(.:format)                     profile#show
#              profile_update PUT    /-/profile/update(.:format)              profile#update
RSpec.describe ProfilesController, "routing" do
  it "to #account" do
    expect(get("/-/profile/account")).to route_to('profiles/accounts#show')
  end
  it_behaves_like 'redirecting a legacy path', '/profile/account', '/-/profile/account'

  it "to #audit_log" do
    expect(get("/-/profile/audit_log")).to route_to('profiles#audit_log')
  end
  it_behaves_like 'redirecting a legacy path', '/profile/audit_log', '/-/profile/audit_log'

  it "to #reset_feed_token" do
    expect(put("/-/profile/reset_feed_token")).to route_to('profiles#reset_feed_token')
  end

  it "to #show" do
    expect(get("/-/profile")).to route_to('profiles#show')
  end
  it_behaves_like 'redirecting a legacy path', '/profile', '/-/profile'
end

# profile_preferences GET      /-/profile/preferences(.:format) profiles/preferences#show
#                     PATCH    /-/profile/preferences(.:format) profiles/preferences#update
#                     PUT      /-/profile/preferences(.:format) profiles/preferences#update
RSpec.describe Profiles::PreferencesController, 'routing' do
  it 'to #show' do
    expect(get('/-/profile/preferences')).to route_to('profiles/preferences#show')
  end
  it_behaves_like 'redirecting a legacy path', '/profile/preferences', '/-/profile/preferences'

  it 'to #update' do
    expect(put('/-/profile/preferences')).to   route_to('profiles/preferences#update')
    expect(patch('/-/profile/preferences')).to route_to('profiles/preferences#update')
  end
end

#     keys GET    /-/profile/keys(.:format)          keys#index
#          POST   /-/profile/keys(.:format)          keys#create
# edit_key GET    /-/profile/keys/:id/edit(.:format) keys#edit
#      key GET    /-/profile/keys/:id(.:format)      keys#show
#          PUT    /-/profile/keys/:id(.:format)      keys#update
#          DELETE /-/profile/keys/:id(.:format)      keys#destroy
RSpec.describe Profiles::KeysController, "routing" do
  it "to #index" do
    expect(get("/-/profile/keys")).to route_to('profiles/keys#index')
  end
  it_behaves_like 'redirecting a legacy path', '/profile/keys', '/-/profile/keys'

  it "to #create" do
    expect(post("/-/profile/keys")).to route_to('profiles/keys#create')
  end

  it "to #show" do
    expect(get("/-/profile/keys/1")).to route_to('profiles/keys#show', id: '1')
  end
  it_behaves_like 'redirecting a legacy path', '/profile/keys/1', '/-/profile/keys/1'

  it "to #destroy" do
    expect(delete("/-/profile/keys/1")).to route_to('profiles/keys#destroy', id: '1')
  end
end

# keys GET    /-/profile/gpg_keys      gpg_keys#index
#  key POST   /-/profile/gpg_keys      gpg_keys#create
#      PUT    /-/profile/gpg_keys/:id  gpg_keys#revoke
#      DELETE /-/profile/gpg_keys/:id  gpg_keys#desroy
RSpec.describe Profiles::GpgKeysController, "routing" do
  it "to #index" do
    expect(get("/-/profile/gpg_keys")).to route_to('profiles/gpg_keys#index')
  end
  it_behaves_like 'redirecting a legacy path', '/profile/gpg_keys', '/-/profile/gpg_keys'

  it "to #create" do
    expect(post("/-/profile/gpg_keys")).to route_to('profiles/gpg_keys#create')
  end

  it "to #destroy" do
    expect(delete("/-/profile/gpg_keys/1")).to route_to('profiles/gpg_keys#destroy', id: '1')
  end
end

#   emails GET    /-/profile/emails(.:format)        emails#index
#          POST   /-/profile/emails(.:format)          emails#create
#          DELETE /-/profile/emails/:id(.:format)      keys#destroy
RSpec.describe Profiles::EmailsController, "routing" do
  it "to #index" do
    expect(get("/-/profile/emails")).to route_to('profiles/emails#index')
  end
  it_behaves_like 'redirecting a legacy path', '/profile/emails', '/-/profile/emails'

  it "to #create" do
    expect(post("/-/profile/emails")).to route_to('profiles/emails#create')
  end

  it "to #destroy" do
    expect(delete("/-/profile/emails/1")).to route_to('profiles/emails#destroy', id: '1')
  end
end

# profile_avatar DELETE /-/profile/avatar(.:format) profiles/avatars#destroy
RSpec.describe Profiles::AvatarsController, "routing" do
  it "to #destroy" do
    expect(delete("/-/profile/avatar")).to route_to('profiles/avatars#destroy')
  end
end

#                dashboard GET    /dashboard(.:format)                dashboard#show
#         dashboard_issues GET    /dashboard/issues(.:format)         dashboard#issues
# dashboard_merge_requests GET    /dashboard/merge_requests(.:format) dashboard#merge_requests
RSpec.describe DashboardController, "routing" do
  it "to #index" do
    expect(get("/dashboard")).to route_to('dashboard/projects#index')
  end

  it "to #issues" do
    expect(get("/dashboard/issues.html")).to route_to('dashboard#issues', format: 'html')
  end

  it "to #calendar_issues" do
    expect(get("/dashboard/issues.ics")).to route_to('dashboard#issues_calendar', format: 'ics')
  end

  it "to #merge_requests" do
    expect(get("/dashboard/merge_requests")).to route_to('dashboard#merge_requests')
  end
end

#                     root        /                                   root#show
RSpec.describe RootController, 'routing' do
  it 'to #index' do
    expect(get('/')).to route_to('root#index')
  end
end

RSpec.describe "Authentication", "routing" do
  it "GET /users/sign_in" do
    expect(get("/users/sign_in")).to route_to('sessions#new')
  end

  it "POST /users/sign_in" do
    expect(post("/users/sign_in")).to route_to('sessions#create')
  end

  it "POST /users/sign_out" do
    expect(post("/users/sign_out")).to route_to('sessions#destroy')
  end

  it "POST /users/password" do
    expect(post("/users/password")).to route_to('passwords#create')
  end

  it "GET /users/password/new" do
    expect(get("/users/password/new")).to route_to('passwords#new')
  end

  it "GET /users/password/edit" do
    expect(get("/users/password/edit")).to route_to('passwords#edit')
  end

  it "PUT /users/password" do
    expect(put("/users/password")).to route_to('passwords#update')
  end

  context 'with LDAP configured' do
    include LdapHelpers

    let(:ldap_settings) { { enabled: true } }

    before do
      stub_ldap_setting(ldap_settings)
      Rails.application.reload_routes!
    end

    after(:all) do
      Rails.application.reload_routes!
    end

    it 'POST /users/auth/ldapmain/callback' do
      expect(post("/users/auth/ldapmain/callback")).to route_to('ldap/omniauth_callbacks#ldapmain')
    end

    context 'with LDAP sign-in disabled' do
      let(:ldap_settings) { { enabled: true, prevent_ldap_sign_in: true } }

      it 'prevents POST /users/auth/ldapmain/callback' do
        expect(post("/users/auth/ldapmain/callback")).not_to be_routable
      end
    end
  end
end

RSpec.describe HealthCheckController, 'routing' do
  it 'to #index' do
    expect(get('/health_check')).to route_to('health_check#index')
  end

  it 'also supports passing checks in the url' do
    expect(get('/health_check/email')).to route_to('health_check#index', checks: 'email')
  end
end

RSpec.describe InvitesController, 'routing' do
  let_it_be(:member) { create(:project_member, :invited) }

  it 'to #show' do
    expect(get("/-/invites/#{member.invite_token}")).to route_to('invites#show', id: member.invite_token)
  end

  it 'to legacy route' do
    expect(get("/invites/#{member.invite_token}")).to route_to('invites#show', id: member.invite_token)
  end
end

RSpec.describe AbuseReportsController, 'routing' do
  let_it_be(:user) { create(:user) }

  it 'to #new' do
    expect(get("/-/abuse_reports/new?user_id=#{user.id}")).to route_to('abuse_reports#new', user_id: user.id.to_s)
  end

  it 'to legacy route' do
    expect(get("/abuse_reports/new?user_id=#{user.id}")).to route_to('abuse_reports#new', user_id: user.id.to_s)
  end
end

RSpec.describe SentNotificationsController, 'routing' do
  it 'to #unsubscribe' do
    expect(get("/-/sent_notifications/4bee17d4a63ed60cf5db53417e9aeb4c/unsubscribe"))
      .to route_to('sent_notifications#unsubscribe', id: '4bee17d4a63ed60cf5db53417e9aeb4c')
  end
end

RSpec.describe AutocompleteController, 'routing' do
  it 'to #users' do
    expect(get("/-/autocomplete/users")).to route_to('autocomplete#users')
  end

  it 'to #projects' do
    expect(get("/-/autocomplete/projects")).to route_to('autocomplete#projects')
  end

  it 'to #award_emojis' do
    expect(get("/-/autocomplete/award_emojis")).to route_to('autocomplete#award_emojis')
  end

  it 'to #merge_request_target_branches' do
    expect(get("/-/autocomplete/merge_request_target_branches")).to route_to('autocomplete#merge_request_target_branches')
  end

  it 'to legacy route' do
    expect(get("/autocomplete/users")).to route_to('autocomplete#users')
    expect(get("/autocomplete/projects")).to route_to('autocomplete#projects')
    expect(get("/autocomplete/award_emojis")).to route_to('autocomplete#award_emojis')
  end
end

RSpec.describe Snippets::BlobsController, "routing" do
  it "to #raw" do
    expect(get('/-/snippets/1/raw/master/lib/version.rb'))
      .to route_to('snippets/blobs#raw', snippet_id: '1', ref: 'master', path: 'lib/version.rb')
  end
end

RSpec.describe RunnerSetupController, 'routing' do
  it 'to #platforms' do
    expect(get("/-/runner_setup/platforms")).to route_to('runner_setup#platforms')
  end
end

# jwks  GET /-/jwks(.:format)  jwks#index
RSpec.describe JwksController, "routing" do
  it "to #index" do
    expect(get('/-/jwks')).to route_to('jwks#index')
  end
end