Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9ab50c86
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ab50c86
编写于
11月 23, 2018
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add specs for runners tokens encryption migration
上级
718ea942
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
86 addition
and
3 deletion
+86
-3
lib/gitlab/background_migration/models/encrypt_columns/settings.rb
...b/background_migration/models/encrypt_columns/settings.rb
+7
-3
spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb
...itlab/background_migration/encrypt_runners_tokens_spec.rb
+79
-0
未找到文件。
lib/gitlab/background_migration/models/encrypt_columns/settings.rb
浏览文件 @
9ab50c86
...
...
@@ -13,13 +13,17 @@ module Gitlab
self
.
table_name
=
'application_settings'
self
.
inheritance_column
=
:_type_disabled
def
runners_token
=
(
value
)
self
.
runners_token_encrypted
=
def
runners_
registration_
token
=
(
value
)
self
.
runners_
registration_
token_encrypted
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
end
def
self
.
encrypted_attributes
{
runners_token:
{
attribute: :runners_token_encrypted
}
}
{
runners_registration_token:
{
attribute: :runners_registration_token_encrypted
}
}
end
end
end
...
...
spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb
0 → 100644
浏览文件 @
9ab50c86
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
EncryptRunnersTokens
,
:migration
,
schema:
20181121111200
do
let
(
:settings
)
{
table
(
:application_settings
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:runners
)
{
table
(
:ci_runners
)
}
context
'when migrating application settings'
do
before
do
settings
.
create!
(
id:
1
,
runners_registration_token:
'plain-text-token1'
)
end
it
'migrates runners registration tokens'
do
migrate!
(
:settings
,
:runners_registration_token
,
1
,
1
)
encrypted_token
=
settings
.
first
.
runners_registration_token_encrypted
decrypted_token
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
encrypted_token
)
expect
(
decrypted_token
).
to
eq
'plain-text-token1'
expect
(
settings
.
first
.
runners_registration_token
).
to
be_nil
end
end
context
'when migrating namespaces'
do
before
do
namespaces
.
create!
(
id:
11
,
name:
'gitlab'
,
path:
'gitlab-org'
,
runners_token:
'my-token1'
)
namespaces
.
create!
(
id:
12
,
name:
'gitlab'
,
path:
'gitlab-org'
,
runners_token:
'my-token2'
)
namespaces
.
create!
(
id:
22
,
name:
'gitlab'
,
path:
'gitlab-org'
,
runners_token:
'my-token3'
)
end
it
'migrates runners registration tokens'
do
migrate!
(
:namespace
,
:runners_token
,
11
,
22
)
expect
(
namespaces
.
all
.
reload
).
to
all
(
have_attributes
(
runners_token:
nil
,
runners_token_encrypted:
be_a
(
String
))
)
end
end
context
'when migrating projects'
do
before
do
namespaces
.
create!
(
id:
11
,
name:
'gitlab'
,
path:
'gitlab-org'
)
projects
.
create!
(
id:
111
,
namespace_id:
11
,
name:
'gitlab'
,
path:
'gitlab-ce'
,
runners_token:
'my-token1'
)
projects
.
create!
(
id:
114
,
namespace_id:
11
,
name:
'gitlab'
,
path:
'gitlab-ce'
,
runners_token:
'my-token2'
)
projects
.
create!
(
id:
116
,
namespace_id:
11
,
name:
'gitlab'
,
path:
'gitlab-ce'
,
runners_token:
'my-token3'
)
end
it
'migrates runners registration tokens'
do
migrate!
(
:project
,
:runners_token
,
111
,
116
)
expect
(
projects
.
all
.
reload
).
to
all
(
have_attributes
(
runners_token:
nil
,
runners_token_encrypted:
be_a
(
String
))
)
end
end
context
'when migrating runners'
do
before
do
runners
.
create!
(
id:
201
,
runner_type:
1
,
token:
'plain-text-token1'
)
runners
.
create!
(
id:
202
,
runner_type:
1
,
token:
'plain-text-token2'
)
runners
.
create!
(
id:
203
,
runner_type:
1
,
token:
'plain-text-token3'
)
end
it
'migrates runners communication tokens'
do
migrate!
(
:runner
,
:token
,
201
,
203
)
expect
(
runners
.
all
.
reload
).
to
all
(
have_attributes
(
token:
nil
,
token_encrypted:
be_a
(
String
))
)
end
end
def
migrate!
(
model
,
attribute
,
from
,
to
)
model
=
"::Gitlab::BackgroundMigration::Models::EncryptColumns::
#{
model
.
to_s
.
capitalize
}
"
subject
.
perform
(
model
,
[
attribute
],
from
,
to
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录