Commit 813221d2 authored by ale's avatar ale

Use a shorter import name for the top-level accountserver package

parent 50f6eaa4
Pipeline #1447 passed with stages
in 2 minutes and 22 seconds
......@@ -5,13 +5,13 @@ import (
"fmt"
"strings"
"git.autistici.org/ai3/accountserver"
as "git.autistici.org/ai3/accountserver"
)
// Extend the AppSpecificPasswordInfo type, which only contains public
// information, with the encrypted password.
type appSpecificPassword struct {
accountserver.AppSpecificPasswordInfo
as.AppSpecificPasswordInfo
Password string
}
......@@ -23,7 +23,7 @@ func (p *appSpecificPassword) Encode() string {
}, ":")
}
func newAppSpecificPassword(info accountserver.AppSpecificPasswordInfo, pw string) *appSpecificPassword {
func newAppSpecificPassword(info as.AppSpecificPasswordInfo, pw string) *appSpecificPassword {
return &appSpecificPassword{
AppSpecificPasswordInfo: info,
Password: pw,
......@@ -35,7 +35,7 @@ func parseAppSpecificPassword(asp string) (*appSpecificPassword, error) {
if len(parts) != 3 {
return nil, errors.New("badly encoded app-specific password")
}
return newAppSpecificPassword(accountserver.AppSpecificPasswordInfo{
return newAppSpecificPassword(as.AppSpecificPasswordInfo{
Service: parts[0],
Comment: parts[2],
}, parts[1]), nil
......@@ -59,22 +59,22 @@ func encodeAppSpecificPasswords(asps []*appSpecificPassword) []string {
return out
}
func getASPInfo(asps []*appSpecificPassword) []*accountserver.AppSpecificPasswordInfo {
var out []*accountserver.AppSpecificPasswordInfo
func getASPInfo(asps []*appSpecificPassword) []*as.AppSpecificPasswordInfo {
var out []*as.AppSpecificPasswordInfo
for _, asp := range asps {
out = append(out, &asp.AppSpecificPasswordInfo)
}
return out
}
func decodeUserEncryptionKeys(values []string) []*accountserver.UserEncryptionKey {
var out []*accountserver.UserEncryptionKey
func decodeUserEncryptionKeys(values []string) []*as.UserEncryptionKey {
var out []*as.UserEncryptionKey
for _, value := range values {
idx := strings.IndexByte(value, ':')
if idx < 0 {
continue
}
out = append(out, &accountserver.UserEncryptionKey{
out = append(out, &as.UserEncryptionKey{
ID: value[:idx],
Key: []byte(value[idx+1:]),
})
......@@ -82,7 +82,7 @@ func decodeUserEncryptionKeys(values []string) []*accountserver.UserEncryptionKe
return out
}
func encodeUserEncryptionKeys(keys []*accountserver.UserEncryptionKey) []string {
func encodeUserEncryptionKeys(keys []*as.UserEncryptionKey) []string {
var out []string
for _, key := range keys {
out = append(out, fmt.Sprintf("%s:%s", key.ID, string(key.Key)))
......
This diff is collapsed.
......@@ -6,7 +6,7 @@ import (
"github.com/go-test/deep"
"git.autistici.org/ai3/accountserver"
as "git.autistici.org/ai3/accountserver"
"git.autistici.org/ai3/accountserver/ldaptest"
)
......@@ -17,15 +17,15 @@ const (
testUser2 = "due@investici.org"
)
func startServerAndGetUser(t testing.TB) (func(), accountserver.Backend, *accountserver.User) {
func startServerAndGetUser(t testing.TB) (func(), as.Backend, *as.User) {
return startServerAndGetUserWithName(t, testUser1)
}
func startServerAndGetUser2(t testing.TB) (func(), accountserver.Backend, *accountserver.User) {
func startServerAndGetUser2(t testing.TB) (func(), as.Backend, *as.User) {
return startServerAndGetUserWithName(t, testUser2)
}
func startServer(t testing.TB) (func(), accountserver.Backend) {
func startServer(t testing.TB) (func(), as.Backend) {
stop := ldaptest.StartServer(t, &ldaptest.Config{
Dir: "../ldaptest",
Port: testLDAPPort,
......@@ -45,7 +45,7 @@ func startServer(t testing.TB) (func(), accountserver.Backend) {
return stop, b
}
func startServerAndGetUserWithName(t testing.TB, username string) (func(), accountserver.Backend, *accountserver.User) {
func startServerAndGetUserWithName(t testing.TB, username string) (func(), as.Backend, *as.User) {
stop, b := startServer(t)
tx, _ := b.NewTransaction()
......@@ -86,25 +86,25 @@ func TestModel_GetUser(t *testing.T) {
}
// Test a specific resource (the database).
db := user.GetSingleResourceByType(accountserver.ResourceTypeDatabase)
expectedDB := &accountserver.Resource{
ID: accountserver.NewResourceID(
accountserver.ResourceTypeDatabase,
db := user.GetSingleResourceByType(as.ResourceTypeDatabase)
expectedDB := &as.Resource{
ID: as.NewResourceID(
as.ResourceTypeDatabase,
testUser1,
"alias=uno",
"unodb",
),
Type: accountserver.ResourceTypeDatabase,
ParentID: accountserver.NewResourceID(
accountserver.ResourceTypeWebsite,
Type: as.ResourceTypeDatabase,
ParentID: as.NewResourceID(
as.ResourceTypeWebsite,
testUser1,
"uno",
),
Name: "unodb",
Shard: "host2",
OriginalShard: "host2",
Status: accountserver.ResourceStatusActive,
Database: &accountserver.Database{
Status: as.ResourceStatusActive,
Database: &as.Database{
CleartextPassword: "password",
DBUser: "unodb",
},
......@@ -168,7 +168,7 @@ func TestModel_SetResourceStatus(t *testing.T) {
}
tx, _ := b.NewTransaction()
rsrcID := accountserver.NewResourceID(accountserver.ResourceTypeEmail, testUser1, testUser1)
rsrcID := as.NewResourceID(as.ResourceTypeEmail, testUser1, testUser1)
r, err := tx.GetResource(context.Background(), rsrcID)
if err != nil {
t.Fatal("GetResource", err)
......@@ -177,7 +177,7 @@ func TestModel_SetResourceStatus(t *testing.T) {
t.Fatalf("could not find test resource %s", rsrcID)
}
r.Status = accountserver.ResourceStatusInactive
r.Status = as.ResourceStatusInactive
if err := tx.UpdateResource(context.Background(), r); err != nil {
t.Fatal("UpdateResource", err)
}
......@@ -203,9 +203,9 @@ func TestModel_HasAnyResource(t *testing.T) {
tx, _ := b.NewTransaction()
// Request that should succeed.
ok, err := tx.HasAnyResource(context.Background(), []accountserver.FindResourceRequest{
{Type: accountserver.ResourceTypeEmail, Name: "foo"},
{Type: accountserver.ResourceTypeEmail, Name: testUser1},
ok, err := tx.HasAnyResource(context.Background(), []as.FindResourceRequest{
{Type: as.ResourceTypeEmail, Name: "foo"},
{Type: as.ResourceTypeEmail, Name: testUser1},
})
if err != nil {
t.Fatal("HasAnyResource", err)
......@@ -215,8 +215,8 @@ func TestModel_HasAnyResource(t *testing.T) {
}
// Request that should fail (bad resource type).
ok, err = tx.HasAnyResource(context.Background(), []accountserver.FindResourceRequest{
{Type: accountserver.ResourceTypeDatabase, Name: testUser1},
ok, err = tx.HasAnyResource(context.Background(), []as.FindResourceRequest{
{Type: as.ResourceTypeDatabase, Name: testUser1},
})
if err != nil {
t.Fatal("HasAnyResource", err)
......@@ -262,9 +262,9 @@ func TestModel_SetUserEncryptionKeys_Add(t *testing.T) {
defer stop()
tx, _ := b.NewTransaction()
keys := []*accountserver.UserEncryptionKey{
keys := []*as.UserEncryptionKey{
{
ID: accountserver.UserEncryptionKeyMainID,
ID: as.UserEncryptionKeyMainID,
Key: []byte("very secret key"),
},
}
......@@ -281,9 +281,9 @@ func TestModel_SetUserEncryptionKeys_Replace(t *testing.T) {
defer stop()
tx, _ := b.NewTransaction()
keys := []*accountserver.UserEncryptionKey{
keys := []*as.UserEncryptionKey{
{
ID: accountserver.UserEncryptionKeyMainID,
ID: as.UserEncryptionKeyMainID,
Key: []byte("very secret key"),
},
}
......
This diff is collapsed.
......@@ -6,7 +6,7 @@ import (
"github.com/go-test/deep"
"gopkg.in/ldap.v2"
"git.autistici.org/ai3/accountserver"
as "git.autistici.org/ai3/accountserver"
)
func TestEmailResource_FromLDAP(t *testing.T) {
......@@ -24,21 +24,21 @@ func TestEmailResource_FromLDAP(t *testing.T) {
)
reg := newResourceRegistry()
reg.register(accountserver.ResourceTypeEmail, &emailResourceHandler{baseDN: "dc=example,dc=com"})
reg.register(as.ResourceTypeEmail, &emailResourceHandler{baseDN: "dc=example,dc=com"})
r, err := reg.FromLDAP(entry)
if err != nil {
t.Fatal("FromLDAP", err)
}
expected := &accountserver.Resource{
ID: accountserver.NewResourceID("email", "test@investici.org", "test@investici.org"),
expected := &as.Resource{
ID: as.NewResourceID("email", "test@investici.org", "test@investici.org"),
Type: "email",
Name: "test@investici.org",
Status: "active",
Shard: "host1",
OriginalShard: "host1",
Email: &accountserver.Email{
Email: &as.Email{
Aliases: []string{"test2@investici.org", "test3@investici.org"},
Maildir: "test/store",
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment