Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2391a9a6
Commit
2391a9a6
authored
Dec 03, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix GCP controller specs
parent
1337a014
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
186 additions
and
1 deletion
+186
-1
app/controllers/projects/clusters/gcp_controller.rb
app/controllers/projects/clusters/gcp_controller.rb
+1
-1
spec/controllers/projects/clusters/gcp_controller_spec.rb
spec/controllers/projects/clusters/gcp_controller_spec.rb
+185
-0
No files found.
app/controllers/projects/clusters/gcp_controller.rb
View file @
2391a9a6
...
@@ -5,7 +5,7 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
...
@@ -5,7 +5,7 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
def
login
def
login
begin
begin
state
=
generate_session_key_redirect
(
new_namespace_project_gcp_url
.
to_s
)
state
=
generate_session_key_redirect
(
gcp_new_namespace_project_clusters_path
.
to_s
)
@authorize_url
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
@authorize_url
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
nil
,
callback_google_api_auth_url
,
nil
,
callback_google_api_auth_url
,
...
...
spec/controllers/projects/clusters/gcp_controller_spec.rb
0 → 100644
View file @
2391a9a6
require
'spec_helper'
describe
Projects
::
Clusters
::
GcpController
do
include
AccessMatchersForController
include
GoogleApi
::
CloudPlatformHelpers
set
(
:project
)
{
create
(
:project
)
}
describe
'GET login'
do
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
'when omniauth has been configured'
do
let
(
:key
)
{
'secere-key'
}
let
(
:session_key_for_redirect_uri
)
do
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_redirect_uri
(
key
)
end
before
do
allow
(
SecureRandom
).
to
receive
(
:hex
).
and_return
(
key
)
end
it
'has authorize_url'
do
go
expect
(
assigns
(
:authorize_url
)).
to
include
(
key
)
expect
(
session
[
session_key_for_redirect_uri
]).
to
eq
(
gcp_new_project_clusters_path
(
project
))
end
end
context
'when omniauth has not configured'
do
before
do
stub_omniauth_setting
(
providers:
[])
end
it
'does not have authorize_url'
do
go
expect
(
assigns
(
:authorize_url
)).
to
be_nil
end
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
get
:login
,
namespace_id:
project
.
namespace
,
project_id:
project
end
end
describe
'GET new'
do
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
'when access token is valid'
do
before
do
stub_google_api_validate_token
end
it
'has new object'
do
go
expect
(
assigns
(
:cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
end
end
context
'when access token is expired'
do
before
do
stub_google_api_expired_token
end
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_namespace_project_clusters_path
(
project
.
namespace
,
project
))
}
end
context
'when access token is not stored in session'
do
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_namespace_project_clusters_path
(
project
.
namespace
,
project
))
}
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
get
:new
,
namespace_id:
project
.
namespace
,
project_id:
project
end
end
describe
'POST create'
do
let
(
:params
)
do
{
cluster:
{
name:
'new-cluster'
,
provider_gcp_attributes:
{
gcp_project_id:
'111'
}
}
}
end
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
'when access token is valid'
do
before
do
stub_google_api_validate_token
end
context
'when creates a cluster on gke'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
.
and
change
{
Clusters
::
Providers
::
Gcp
.
count
}
expect
(
response
).
to
redirect_to
(
project_cluster_path
(
project
,
project
.
cluster
))
expect
(
project
.
cluster
).
to
be_gcp
expect
(
project
.
cluster
).
to
be_kubernetes
end
end
end
context
'when access token is expired'
do
before
do
stub_google_api_expired_token
end
it
'redirects to login page'
do
expect
(
go
).
to
redirect_to
(
gcp_login_namespace_project_clusters_path
(
project
.
namespace
,
project
))
end
end
context
'when access token is not stored in session'
do
it
'redirects to login page'
do
expect
(
go
).
to
redirect_to
(
gcp_login_namespace_project_clusters_path
(
project
.
namespace
,
project
))
end
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment