Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
e75ab064
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,发现更多精彩内容 >>
提交
e75ab064
编写于
6月 15, 2017
作者:
A
Alexis Reigel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update invalid gpg signatures when email changes
上级
24671cd6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
90 addition
and
29 deletion
+90
-29
app/models/gpg_key.rb
app/models/gpg_key.rb
+4
-4
app/models/user.rb
app/models/user.rb
+5
-0
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
+61
-25
spec/models/user_spec.rb
spec/models/user_spec.rb
+20
-0
未找到文件。
app/models/gpg_key.rb
浏览文件 @
e75ab064
...
...
@@ -53,6 +53,10 @@ class GpgKey < ActiveRecord::Base
emails_with_verified_status
.
any?
{
|
_email
,
verified
|
verified
}
end
def
update_invalid_gpg_signatures
Gitlab
::
Gpg
::
InvalidGpgSignatureUpdater
.
new
(
self
).
run
end
private
def
extract_fingerprint
...
...
@@ -67,10 +71,6 @@ class GpgKey < ActiveRecord::Base
self
.
primary_keyid
=
Gitlab
::
Gpg
.
primary_keyids_from_key
(
key
).
first
end
def
update_invalid_gpg_signatures
run_after_commit
{
Gitlab
::
Gpg
::
InvalidGpgSignatureUpdater
.
new
(
self
).
run
}
end
def
notify_user
run_after_commit
{
NotificationService
.
new
.
new_gpg_key
(
self
)
}
end
...
...
app/models/user.rb
浏览文件 @
e75ab064
...
...
@@ -155,6 +155,7 @@ class User < ActiveRecord::Base
before_validation
:set_public_email
,
if: :public_email_changed?
after_update
:update_emails_with_primary_email
,
if: :email_changed?
after_update
:update_invalid_gpg_signatures
,
if: :email_changed?
before_save
:ensure_authentication_token
,
:ensure_incoming_email_token
before_save
:ensure_user_rights_and_limits
,
if: :external_changed?
after_save
:ensure_namespace_correct
...
...
@@ -513,6 +514,10 @@ class User < ActiveRecord::Base
end
end
def
update_invalid_gpg_signatures
gpg_keys
.
each
(
&
:update_invalid_gpg_signatures
)
end
# Returns the groups a user has access to
def
authorized_groups
union
=
Gitlab
::
SQL
::
Union
...
...
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
浏览文件 @
e75ab064
...
...
@@ -2,37 +2,39 @@ require 'rails_helper'
RSpec
.
describe
Gitlab
::
Gpg
::
InvalidGpgSignatureUpdater
do
describe
'#run'
do
context
'gpg signature did not have an associated gpg key'
do
let!
(
:commit_sha
)
{
'0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
}
let!
(
:project
)
{
create
:project
,
:repository
,
path:
'sample-project'
}
let!
(
:commit
)
do
raw_commit
=
double
(
:raw_commit
,
signature:
[
GpgHelpers
::
User1
.
signed_commit_signature
,
GpgHelpers
::
User1
.
signed_commit_base_data
],
sha:
commit_sha
)
allow
(
raw_commit
).
to
receive
:save!
create
:commit
,
git_commit:
raw_commit
,
project:
project
end
let!
(
:commit_sha
)
{
'0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
}
let!
(
:project
)
{
create
:project
,
:repository
,
path:
'sample-project'
}
let!
(
:commit
)
do
raw_commit
=
double
(
:raw_commit
,
signature:
[
GpgHelpers
::
User1
.
signed_commit_signature
,
GpgHelpers
::
User1
.
signed_commit_base_data
],
sha:
commit_sha
)
allow
(
raw_commit
).
to
receive
:save!
let!
(
:gpg_signature
)
do
create
:gpg_signature
,
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
end
create
:commit
,
git_commit:
raw_commit
,
project:
project
end
before
do
allow
(
Gitlab
::
Git
::
Commit
).
to
receive
(
:find
).
with
(
kind_of
(
Repository
),
commit_sha
).
and_return
(
commit
)
end
let!
(
:gpg_signature
)
do
create
:gpg_signature
,
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
end
before
do
allow
(
Gitlab
::
Git
::
Commit
).
to
receive
(
:find
).
with
(
kind_of
(
Repository
),
commit_sha
).
and_return
(
commit
)
end
context
'gpg signature did not have an associated gpg key'
do
let!
(
:user
)
{
create
:user
,
email:
GpgHelpers
::
User1
.
emails
.
first
}
it
'updates the signature to being valid when the missing gpg key is added'
do
# InvalidGpgSignatureUpdater is called by the after_create hook
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
create
(
:user
,
email:
GpgHelpers
::
User1
.
emails
.
first
)
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
end
...
...
@@ -41,7 +43,41 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
# InvalidGpgSignatureUpdater is called by the after_create hook
create
:gpg_key
,
key:
GpgHelpers
::
User2
.
public_key
,
user:
create
(
:user
,
email:
GpgHelpers
::
User2
.
emails
.
first
)
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
end
end
context
'gpg signature did have an associated unverified gpg key'
do
let!
(
:user
)
do
create
(
:user
,
email:
'unrelated@example.com'
).
tap
do
|
user
|
user
.
skip_reconfirmation!
end
end
it
'updates the signature to being valid when the user updates the email address'
do
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
# InvalidGpgSignatureUpdater is called by the after_update hook
user
.
update_attributes!
(
email:
GpgHelpers
::
User1
.
emails
.
first
)
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
end
it
'keeps the signature at being invalid when the changed email address is still unrelated'
do
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
# InvalidGpgSignatureUpdater is called by the after_update hook
user
.
update_attributes!
(
email:
'still.unrelated@example.com'
)
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
end
...
...
spec/models/user_spec.rb
浏览文件 @
e75ab064
...
...
@@ -350,6 +350,26 @@ describe User, models: true do
end
end
describe
'after update hook'
do
describe
'.update_invalid_gpg_signatures'
do
let
(
:user
)
do
create
(
:user
,
email:
'tula.torphy@abshire.ca'
).
tap
do
|
user
|
user
.
skip_reconfirmation!
end
end
it
'does nothing when the name is updated'
do
expect
(
user
).
not_to
receive
(
:update_invalid_gpg_signatures
)
user
.
update_attributes!
(
name:
'Bette'
)
end
it
'synchronizes the gpg keys when the email is updated'
do
expect
(
user
).
to
receive
(
:update_invalid_gpg_signatures
)
user
.
update_attributes!
(
email:
'shawnee.ritchie@denesik.com'
)
end
end
end
describe
'#update_tracked_fields!'
,
:clean_gitlab_redis_shared_state
do
let
(
:request
)
{
OpenStruct
.
new
(
remote_ip:
"127.0.0.1"
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录