(t *testing.T)
| 75 | } |
| 76 | |
| 77 | func TestParseUsers(t *testing.T) { |
| 78 | // Valid users |
| 79 | users, err := utils.ParseUsers([]string{"user1:$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G", "user2:$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G:ABCDEF"}) // user2 has TOTP |
| 80 | |
| 81 | assert.NilError(t, err) |
| 82 | |
| 83 | assert.Equal(t, 2, len(users)) |
| 84 | |
| 85 | assert.Equal(t, "user1", users[0].Username) |
| 86 | assert.Equal(t, "$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G", users[0].Password) |
| 87 | assert.Equal(t, "", users[0].TotpSecret) |
| 88 | assert.Equal(t, "user2", users[1].Username) |
| 89 | assert.Equal(t, "$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G", users[1].Password) |
| 90 | assert.Equal(t, "ABCDEF", users[1].TotpSecret) |
| 91 | |
| 92 | // Valid weirdly spaced users |
| 93 | users, err = utils.ParseUsers([]string{" user1:$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G ", " user2:$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G:ABCDEF "}) // Spacing is on purpose |
| 94 | assert.NilError(t, err) |
| 95 | |
| 96 | assert.Equal(t, 2, len(users)) |
| 97 | |
| 98 | assert.Equal(t, "user1", users[0].Username) |
| 99 | assert.Equal(t, "$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G", users[0].Password) |
| 100 | assert.Equal(t, "", users[0].TotpSecret) |
| 101 | assert.Equal(t, "user2", users[1].Username) |
| 102 | assert.Equal(t, "$2a$10$Mz5xhkfSJUtPWkzCd/TdaePh9CaXc5QcGII5wIMPLSR46eTwma30G", users[1].Password) |
| 103 | assert.Equal(t, "ABCDEF", users[1].TotpSecret) |
| 104 | } |
| 105 | |
| 106 | func TestParseUser(t *testing.T) { |
| 107 | // Valid user without TOTP |
nothing calls this directly
no test coverage detected