Skip to content
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

[Unit Tests] - PersonIsAdmin #2275

Closed
tomsmith8 opened this issue Dec 23, 2024 · 3 comments · Fixed by #2284
Closed

[Unit Tests] - PersonIsAdmin #2275

tomsmith8 opened this issue Dec 23, 2024 · 3 comments · Fixed by #2284
Assignees
Labels

Comments

@tomsmith8
Copy link

Unit Test Coverage for "PersonIsAdmin"


Stakwork Run


Unit Test Code


File: /tmp/stakwork/sphinx-tribes/handlers/people.go


package handlers

import (
  "os"
  "strings"
  "testing"

  "github.com/stretchr/testify/assert"
)

func TestPersonIsAdmin(t *testing.T) {
  tests := []struct {
  	name         string
  	adminPubkeys string
  	pk           string
  	expected     bool
  }{
  	{
  		name:         "Single Admin Key Match",
  		adminPubkeys: "admin1",
  		pk:           "admin1",
  		expected:     true,
  	},
  	{
  		name:         "Multiple Admin Keys Match",
  		adminPubkeys: "admin1,admin2,admin3",
  		pk:           "admin2",
  		expected:     true,
  	},
  	{
  		name:         "No Match with Single Admin Key",
  		adminPubkeys: "admin1",
  		pk:           "admin2",
  		expected:     false,
  	},
  	{
  		name:         "No Match with Multiple Admin Keys",
  		adminPubkeys: "admin1,admin2,admin3",
  		pk:           "admin4",
  		expected:     false,
  	},
  	{
  		name:         "Empty Admin Keys",
  		adminPubkeys: "",
  		pk:           "admin1",
  		expected:     false,
  	},
  	{
  		name:         "Empty Input Key",
  		adminPubkeys: "admin1,admin2",
  		pk:           "",
  		expected:     false,
  	},
  	{
  		name:         "Whitespace in Admin Keys",
  		adminPubkeys: " admin1 , admin2 ",
  		pk:           "admin1",
  		expected:     true,
  	},
  	{
  		name:         "Whitespace in Input Key",
  		adminPubkeys: "admin1,admin2",
  		pk:           " admin1 ",
  		expected:     false,
  	},
  	{
  		name:         "Null Input Key",
  		adminPubkeys: "admin1,admin2",
  		pk:           "",
  		expected:     false,
  	},
  	{
  		name:         "Non-String Input Key",
  		adminPubkeys: "admin1,admin2",
  		pk:           "123",
  		expected:     false,
  	},
  	{
  		name:         "Large Number of Admin Keys",
  		adminPubkeys: strings.Repeat("admin,", 9999) + "admin9999",
  		pk:           "admin9999",
  		expected:     true,
  	},
  	{
  		name:         "Long Admin Key",
  		adminPubkeys: strings.Repeat("a", 1000),
  		pk:           strings.Repeat("a", 1000),
  		expected:     true,
  	},
  	{
  		name:         "Case Sensitivity",
  		adminPubkeys: "Admin1",
  		pk:           "admin1",
  		expected:     false,
  	},
  	{
  		name:         "Special Characters in Admin Keys",
  		adminPubkeys: "admin@1,admin#2",
  		pk:           "admin@1",
  		expected:     true,
  	},
  	{
  		name:         "Comma at the End of Admin Keys",
  		adminPubkeys: "admin1,admin2,",
  		pk:           "admin2",
  		expected:     true,
  	},
  	{
  		name:         "Duplicate Admin Keys",
  		adminPubkeys: "admin1,admin1,admin2",
  		pk:           "admin1",
  		expected:     true,
  	},
  	{
  		name:         "Empty String in Admin Keys",
  		adminPubkeys: "admin1,,admin2",
  		pk:           "",
  		expected:     false,
  	},
  }

  for _, tt := range tests {
  	t.Run(tt.name, func(t *testing.T) {
  		os.Setenv("ADMIN_PUBKEYS", tt.adminPubkeys)
  		result := PersonIsAdmin(tt.pk)
  		assert.Equal(t, tt.expected, result)
  	})
  }
}
@Shoaibdev7
Copy link
Contributor

@tomsmith8 could you assign me?

@MuhammadUmer44
Copy link
Contributor

@tomsmith8 Please assign me?

@MahtabBukhari
Copy link
Contributor

@tomsmith8 please assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants