-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Writable deploy keys (closes #671) #3225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+184
−13
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9d44308
Add is_writable checkbox to deploy keys interface
vtemian 0bb3228
Add writable key option to deploy key form
vtemian 147063e
Add support for writable ssh keys in the interface
vtemian e4315d9
Rename IsWritable to ReadOnly
vtemian 96e85d7
Test: create read-only and read-write deploy keys via api
vtemian 8becb7e
Add DeployKey access mode migration
vtemian 1142740
Update gitea sdk via govendor
vtemian 1dc6f3e
Fix deploykey migration
vtemian 9256cf6
Add unittests for writable deploy keys
vtemian dde53ee
Move template text to locale
vtemian 5ec7d62
Remove implicit column update
vtemian 328d9f2
Remove duplicate locales
vtemian d5bc046
Replace ReadOnly field with IsReadOnly method
vtemian af5191c
Fix deploy_keys related integration test
vtemian 9337688
Rename v54 migration with v55
vtemian b3e094e
Fix migration hell
vtemian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] # empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models" | ||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
func addModeToDeploKeys(x *xorm.Engine) error { | ||
type DeployKey struct { | ||
Mode models.AccessMode `xorm:"NOT NULL DEFAULT 1"` | ||
} | ||
|
||
if err := x.Sync2(new(DeployKey)); err != nil { | ||
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package repo | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/auth" | ||
"code.gitea.io/gitea/modules/test" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAddReadOnlyDeployKey(t *testing.T) { | ||
models.PrepareTestEnv(t) | ||
|
||
ctx := test.MockContext(t, "user2/repo1/settings/keys") | ||
|
||
test.LoadUser(t, ctx, 2) | ||
test.LoadRepo(t, ctx, 2) | ||
|
||
addKeyForm := auth.AddKeyForm{ | ||
Title: "read-only", | ||
Content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment\n", | ||
} | ||
DeployKeysPost(ctx, addKeyForm) | ||
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) | ||
|
||
models.AssertExistsAndLoadBean(t, &models.DeployKey{ | ||
Name: addKeyForm.Title, | ||
Content: addKeyForm.Content, | ||
Mode: models.AccessModeRead, | ||
}) | ||
} | ||
|
||
func TestAddReadWriteOnlyDeployKey(t *testing.T) { | ||
models.PrepareTestEnv(t) | ||
|
||
ctx := test.MockContext(t, "user2/repo1/settings/keys") | ||
|
||
test.LoadUser(t, ctx, 2) | ||
test.LoadRepo(t, ctx, 2) | ||
|
||
addKeyForm := auth.AddKeyForm{ | ||
Title: "read-write", | ||
Content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment\n", | ||
IsWritable: true, | ||
} | ||
DeployKeysPost(ctx, addKeyForm) | ||
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) | ||
|
||
models.AssertExistsAndLoadBean(t, &models.DeployKey{ | ||
Name: addKeyForm.Title, | ||
Content: addKeyForm.Content, | ||
Mode: models.AccessModeWrite, | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for adding tests!
However, our suite of integration tests is becoming quite unwieldy. Would you consider instead writing equivalent unit tests for the
DeployKeysPost
handler? See routers/repo/issue_label_test.go for some examples.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote the unit tests, but I don't know if it's ok to dump the integration tests.
Those are testing the API and the unit tests the interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's leave the integration tests. Eventually, it might make sense to convert our API integration tests to unit tests, but that's for another day. Thanks for adding unit tests!