You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/auth"
  10. "code.gitea.io/gitea/modules/test"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestAddReadOnlyDeployKey(t *testing.T) {
  14. models.PrepareTestEnv(t)
  15. ctx := test.MockContext(t, "user2/repo1/settings/keys")
  16. test.LoadUser(t, ctx, 2)
  17. test.LoadRepo(t, ctx, 2)
  18. addKeyForm := auth.AddKeyForm{
  19. Title: "read-only",
  20. Content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment\n",
  21. }
  22. DeployKeysPost(ctx, addKeyForm)
  23. assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
  24. models.AssertExistsAndLoadBean(t, &models.DeployKey{
  25. Name: addKeyForm.Title,
  26. Content: addKeyForm.Content,
  27. Mode: models.AccessModeRead,
  28. })
  29. }
  30. func TestAddReadWriteOnlyDeployKey(t *testing.T) {
  31. models.PrepareTestEnv(t)
  32. ctx := test.MockContext(t, "user2/repo1/settings/keys")
  33. test.LoadUser(t, ctx, 2)
  34. test.LoadRepo(t, ctx, 2)
  35. addKeyForm := auth.AddKeyForm{
  36. Title: "read-write",
  37. Content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment\n",
  38. IsWritable: true,
  39. }
  40. DeployKeysPost(ctx, addKeyForm)
  41. assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
  42. models.AssertExistsAndLoadBean(t, &models.DeployKey{
  43. Name: addKeyForm.Title,
  44. Content: addKeyForm.Content,
  45. Mode: models.AccessModeWrite,
  46. })
  47. }