Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
208afd3b
Commit
208afd3b
authored
Mar 01, 2016
by
Eric Chiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*: add functional tests for case insensitive emails
parent
9bc68eda
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
5 deletions
+108
-5
migrate_test.go
db/migrate_test.go
+86
-0
user_repo_test.go
functional/repo/user_repo_test.go
+22
-5
No files found.
db/migrate_test.go
View file @
208afd3b
...
...
@@ -3,10 +3,12 @@ package db
import
(
"fmt"
"os"
"sort"
"strconv"
"testing"
"github.com/go-gorp/gorp"
"github.com/kylelemons/godebug/pretty"
)
func
initDB
(
dsn
string
)
*
gorp
.
DbMap
{
...
...
@@ -14,6 +16,9 @@ func initDB(dsn string) *gorp.DbMap {
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"error making db connection: %q"
,
err
))
}
if
_
,
err
:=
c
.
Exec
(
fmt
.
Sprintf
(
"DROP TABLE IF EXISTS %s;"
,
migrationTable
));
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"failed to drop migration table: %v"
,
err
))
}
if
err
=
c
.
DropTablesIfExists
();
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"Unable to drop database tables: %v"
,
err
))
}
...
...
@@ -119,3 +124,84 @@ func TestMigrateClientMetadata(t *testing.T) {
}
}
}
func
TestMigrationNumber11
(
t
*
testing
.
T
)
{
dsn
:=
os
.
Getenv
(
"DEX_TEST_DSN"
)
if
dsn
==
""
{
t
.
Skip
(
"Test will not run without DEX_TEST_DSN environment variable."
)
return
}
tests
:=
[]
struct
{
sqlStmt
string
wantEmails
[]
string
wantError
bool
}{
{
sqlStmt
:
`INSERT INTO authd_user
(id, email, email_verified, display_name, admin, created_at)
VALUES
(1, 'Foo@example.com', TRUE, 'foo', FALSE, extract(epoch from now())),
(2, 'Bar@example.com', TRUE, 'foo', FALSE, extract(epoch from now()))
;`
,
wantEmails
:
[]
string
{
"foo@example.com"
,
"bar@example.com"
},
wantError
:
false
,
},
{
sqlStmt
:
`INSERT INTO authd_user
(id, email, email_verified, display_name, admin, created_at)
VALUES
(1, 'Foo@example.com', TRUE, 'foo', FALSE, extract(epoch from now())),
(2, 'foo@example.com', TRUE, 'foo', FALSE, extract(epoch from now())),
(3, 'bar@example.com', TRUE, 'foo', FALSE, extract(epoch from now()))
;`
,
wantError
:
true
,
},
}
migrateN
:=
func
(
dbMap
*
gorp
.
DbMap
,
n
int
)
error
{
nPerformed
,
err
:=
MigrateMaxMigrations
(
dbMap
,
n
)
if
err
==
nil
&&
n
!=
nPerformed
{
err
=
fmt
.
Errorf
(
"expected to perform %d migrations, performed %d"
,
n
,
nPerformed
)
}
return
err
}
for
i
,
tt
:=
range
tests
{
err
:=
func
()
error
{
dbMap
:=
initDB
(
dsn
)
nMigrations
:=
10
if
err
:=
migrateN
(
dbMap
,
nMigrations
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to perform initial migration: %v"
,
err
)
}
if
_
,
err
:=
dbMap
.
Exec
(
tt
.
sqlStmt
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to insert users: %v"
,
err
)
}
if
err
:=
migrateN
(
dbMap
,
1
);
err
!=
nil
{
if
tt
.
wantError
{
return
nil
}
return
fmt
.
Errorf
(
"failed to perform migration: %v"
,
err
)
}
if
tt
.
wantError
{
return
fmt
.
Errorf
(
"expected an error when migrating"
)
}
var
gotEmails
[]
string
if
_
,
err
:=
dbMap
.
Select
(
&
gotEmails
,
`SELECT email FROM authd_user;`
);
err
!=
nil
{
return
fmt
.
Errorf
(
"could not get user emails: %v"
,
err
)
}
sort
.
Strings
(
tt
.
wantEmails
)
sort
.
Strings
(
gotEmails
)
if
diff
:=
pretty
.
Compare
(
tt
.
wantEmails
,
gotEmails
);
diff
!=
""
{
return
fmt
.
Errorf
(
"wantEmails != gotEmails: %s"
,
diff
)
}
return
nil
}()
if
err
!=
nil
{
t
.
Errorf
(
"case %d: %v"
,
i
,
err
)
}
}
}
functional/repo/user_repo_test.go
View file @
208afd3b
...
...
@@ -104,6 +104,15 @@ func TestNewUser(t *testing.T) {
},
err
:
user
.
ErrorDuplicateEmail
,
},
{
user
:
user
.
User
{
ID
:
"ID-same"
,
Email
:
"email-1@example.com"
,
DisplayName
:
"A lower case version of the original email"
,
CreatedAt
:
now
,
},
err
:
user
.
ErrorDuplicateEmail
,
},
{
user
:
user
.
User
{
Email
:
"AnotherEmail@example.com"
,
...
...
@@ -421,12 +430,19 @@ func findRemoteIdentity(rids []user.RemoteIdentity, rid user.RemoteIdentity) int
func
TestGetByEmail
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
email
string
wantErr
error
email
string
wantEmail
string
wantErr
error
}{
{
email
:
"Email-1@example.com"
,
wantErr
:
nil
,
email
:
"Email-1@example.com"
,
wantEmail
:
"Email-1@example.com"
,
wantErr
:
nil
,
},
{
email
:
"EMAIL-1@example.com"
,
// Emails should be case insensitive.
wantEmail
:
"Email-1@example.com"
,
wantErr
:
nil
,
},
{
email
:
"NoSuchEmail@example.com"
,
...
...
@@ -446,9 +462,10 @@ func TestGetByEmail(t *testing.T) {
if
gotErr
!=
nil
{
t
.
Errorf
(
"case %d: want nil err:% q"
,
i
,
gotErr
)
continue
}
if
tt
.
e
mail
!=
gotUser
.
Email
{
if
tt
.
wantE
mail
!=
gotUser
.
Email
{
t
.
Errorf
(
"case %d: want=%q, got=%q"
,
i
,
tt
.
email
,
gotUser
.
Email
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment