Skip to content

Commit 86a4917

Browse files
committed
Reworked KBase user federation logic. Not quite working yet.
1 parent 94563de commit 86a4917

File tree

9 files changed

+389
-212
lines changed

9 files changed

+389
-212
lines changed

auth/kbase_auth_server.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,13 @@ func NewKBaseAuthServer(accessToken string) (*KBaseAuthServer, error) {
5959
}
6060

6161
// verify that the access token works (i.e. that the client is logged in)
62-
kbaseUser, err := server.kbaseUser()
62+
_, err := server.kbaseUser()
6363
if err != nil {
6464
return nil, err
6565
}
6666

67-
// register the local username under all its ORCIDs with our KBase user
68-
// federation mechanism
69-
for _, pid := range kbaseUser.Idents {
70-
if pid.Provider == "OrcID" {
71-
orcid := pid.UserName
72-
err = SetKBaseLocalUsernameForOrcid(orcid, kbaseUser.Username)
73-
if err != nil {
74-
break
75-
}
76-
}
77-
}
78-
79-
if err == nil {
80-
// register this instance of the auth server
81-
instances[accessToken] = &server
82-
}
67+
// register this instance of the auth server
68+
instances[accessToken] = &server
8369
return &server, err
8470
}
8571
}

auth/kbase_user_federation.go

Lines changed: 0 additions & 112 deletions
This file was deleted.

auth/kbase_user_federation_test.go

Lines changed: 0 additions & 73 deletions
This file was deleted.

databases/jdp/database_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ databases:
1818
jdp:
1919
name: JGI Data Portal
2020
organization: Joint Genome Institue
21-
url: https://files.jgi.doe.gov
2221
endpoint: globus-jdp
23-
auth:
24-
client_id: ${JGI_CLIENT_ID}
25-
client_secret: ${JGI_CLIENT_SECRET}
2622
endpoints:
2723
globus-jdp:
2824
name: Globus NERSC DTN
@@ -105,7 +101,7 @@ func TestResources(t *testing.T) {
105101
assert.Nil(err, "JDP resource query encountered an error")
106102
assert.Equal(10, len(resources),
107103
"JDP resource query didn't return requested number of results")
108-
for i, _ := range resources {
104+
for i := range resources {
109105
jdpSearchResult := results.Resources[i]
110106
resource := resources[i]
111107
assert.Equal(jdpSearchResult.Id, resource.Id, "Resource ID mismatch")

databases/kbase/database.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
"github.com/google/uuid"
2828

29-
"github.com/kbase/dts/auth"
3029
"github.com/kbase/dts/databases"
3130
"github.com/kbase/dts/frictionless"
3231
)
@@ -43,6 +42,8 @@ func NewDatabase(orcid string) (databases.Database, error) {
4342
return nil, fmt.Errorf("No ORCID was given")
4443
}
4544

45+
startUserFederation()
46+
4647
return &Database{
4748
Id: "kbase",
4849
}, nil
@@ -73,9 +74,7 @@ func (db *Database) StagingStatus(id uuid.UUID) (databases.StagingStatus, error)
7374
}
7475

7576
func (db *Database) LocalUser(orcid string) (string, error) {
76-
// for KBase user federation, we rely on a table maintained by our KBase
77-
// auth server proxy
78-
return auth.KBaseLocalUsernameForOrcid(orcid)
77+
return usernameForOrcid(orcid)
7978
}
8079

8180
func (db Database) Save() (databases.DatabaseSaveState, error) {

databases/kbase/database_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package kbase
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/kbase/dts/config"
10+
"github.com/kbase/dts/databases"
11+
"github.com/kbase/dts/dtstest"
12+
"github.com/kbase/dts/endpoints"
13+
"github.com/kbase/dts/endpoints/globus"
14+
)
15+
16+
const kbaseConfig string = `
17+
databases:
18+
kbase:
19+
name: KBase Workspace Service (KSS)
20+
organization: KBase
21+
endpoint: globus-kbase
22+
endpoints:
23+
globus-kbase:
24+
name: KBase
25+
id: ${DTS_GLOBUS_TEST_ENDPOINT}
26+
provider: globus
27+
auth:
28+
client_id: ${DTS_GLOBUS_CLIENT_ID}
29+
client_secret: ${DTS_GLOBUS_CLIENT_SECRET}
30+
`
31+
32+
// this function gets called at the begіnning of a test session
33+
func setup() {
34+
dtstest.EnableDebugLogging()
35+
config.Init([]byte(kbaseConfig))
36+
databases.RegisterDatabase("kbase", NewDatabase)
37+
endpoints.RegisterEndpointProvider("globus", globus.NewEndpoint)
38+
}
39+
40+
// this function gets called after all tests have been run
41+
func breakdown() {
42+
}
43+
44+
func TestNewDatabase(t *testing.T) {
45+
assert := assert.New(t)
46+
orcid := os.Getenv("DTS_KBASE_TEST_ORCID")
47+
db, err := NewDatabase(orcid)
48+
assert.NotNil(db, "KBase database not created")
49+
assert.Nil(err, "KBase database creation encountered an error")
50+
}
51+
52+
func TestNewDatabaseWithoutOrcid(t *testing.T) {
53+
assert := assert.New(t)
54+
db, err := NewDatabase("")
55+
assert.Nil(db, "Invalid KBase database somehow created")
56+
assert.NotNil(err, "KBase database creation without ORCID encountered no error")
57+
}
58+
59+
func TestSearch(t *testing.T) {
60+
assert := assert.New(t)
61+
orcid := os.Getenv("DTS_KBASE_TEST_ORCID")
62+
db, _ := NewDatabase(orcid)
63+
params := databases.SearchParameters{
64+
Query: "prochlorococcus",
65+
Pagination: struct {
66+
Offset, MaxNum int
67+
}{
68+
Offset: 1,
69+
MaxNum: 50,
70+
},
71+
}
72+
_, err := db.Search(params)
73+
assert.NotNil(err, "Search not implemented for kbase database!")
74+
}
75+
76+
func TestResources(t *testing.T) {
77+
assert := assert.New(t)
78+
orcid := os.Getenv("DTS_KBASE_TEST_ORCID")
79+
db, _ := NewDatabase(orcid)
80+
_, err := db.Resources(nil)
81+
assert.NotNil(err, "Resources not implemented for kbase database!")
82+
}
83+
84+
func TestLocalUser(t *testing.T) {
85+
assert := assert.New(t)
86+
orcid := os.Getenv("DTS_KBASE_TEST_ORCID")
87+
db, _ := NewDatabase(orcid)
88+
username, err := db.LocalUser(orcid)
89+
assert.Nil(err)
90+
assert.True(len(username) > 0)
91+
}
92+
93+
// this runs setup, runs all tests, and does breakdown
94+
func TestMain(m *testing.M) {
95+
setup()
96+
status := m.Run()
97+
breakdown()
98+
os.Exit(status)
99+
}

0 commit comments

Comments
 (0)