Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 8cb7169

Browse files
committed
config: email address is now obtained from the user certificate
1 parent 45f0c9b commit 8cb7169

3 files changed

Lines changed: 35 additions & 33 deletions

File tree

cmd/dio_test.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ cloud = "%s"
4444
4545
[user]
4646
name = "Some One"
47-
email = "someone@example.org"
4847
`
4948
)
5049

@@ -135,10 +134,12 @@ func (s *DioSuite) SetUpSuite(c *chk.C) {
135134
log.Fatalln(err)
136135
}
137136
TLSConfig.Certificates = []tls.Certificate{cert}
138-
certUser, _, err = getUserAndServer()
137+
var email string
138+
certUser, email, _, err = getUserAndServer()
139139
if err != nil {
140140
log.Fatalln(err)
141141
}
142+
viper.Set("user.email", email)
142143

143144
// Add test database
144145
s.dbName = "19kB.sqlite"
@@ -236,7 +237,7 @@ func (s *DioSuite) Test0010_Commit(c *chk.C) {
236237
c.Check(meta.Commits, chk.HasLen, 1)
237238

238239
// Verify the values in the commit data match the values we provided
239-
com, ok := meta.Commits["485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb"] // This commit ID is what the given values should generate a commit ID as
240+
com, ok := meta.Commits["59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941"] // This commit ID is what the given values should generate a commit ID as
240241
c.Assert(ok, chk.Equals, true)
241242
c.Check(com.AuthorName, chk.Equals, commitCmdAuthName)
242243
c.Check(com.AuthorEmail, chk.Equals, commitCmdAuthEmail)
@@ -245,8 +246,8 @@ func (s *DioSuite) Test0010_Commit(c *chk.C) {
245246
c.Check(com.Parent, chk.Equals, "")
246247
c.Check(com.OtherParents, chk.IsNil)
247248
c.Check(com.CommitterName, chk.Equals, "Some One")
248-
c.Check(com.CommitterEmail, chk.Equals, "someone@example.org")
249-
c.Check(com.ID, chk.Equals, "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb")
249+
c.Check(com.CommitterEmail, chk.Equals, "default@docker-dev.dbhub.io")
250+
c.Check(com.ID, chk.Equals, "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941")
250251
c.Check(com.Tree.Entries[0].EntryType, chk.Equals, dbTreeEntryType(DATABASE))
251252
c.Check(com.Tree.Entries[0].LastModified.UTC(), chk.Equals, time.Date(2019, time.March, 15, 18, 1, 0, 0, time.UTC))
252253
c.Check(com.Tree.Entries[0].LicenceSHA, chk.Equals, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") // e3b... is the SHA256 for the "Not specified" licence option
@@ -269,7 +270,7 @@ func (s *DioSuite) Test0010_Commit(c *chk.C) {
269270
// Verify the branch info
270271
br, ok := meta.Branches["master"]
271272
c.Assert(ok, chk.Equals, true)
272-
c.Check(br.Commit, chk.Equals, "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb")
273+
c.Check(br.Commit, chk.Equals, "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941")
273274
c.Check(br.CommitCount, chk.Equals, 1)
274275
c.Check(br.Description, chk.Equals, "")
275276
}
@@ -294,17 +295,17 @@ func (s *DioSuite) Test0020_Commit2(c *chk.C) {
294295
c.Check(meta.Commits, chk.HasLen, 2)
295296

296297
// Verify the values in the commit data match the values we provided
297-
com, ok := meta.Commits["9c4eab0f96134063f856fc48604f49c7c1e225a79f3eebc4e226dc01b4cfe9bc"] // This commit ID is what the given values should generate a commit ID as
298+
com, ok := meta.Commits["70815d687cfc614b23dfb2f66f8fa0a8cb7bad199e05d4142db883690eefeba5"] // This commit ID is what the given values should generate a commit ID as
298299
c.Assert(ok, chk.Equals, true)
299300
c.Check(com.AuthorName, chk.Equals, commitCmdAuthName)
300301
c.Check(com.AuthorEmail, chk.Equals, commitCmdAuthEmail)
301302
c.Check(com.Message, chk.Equals, commitCmdMsg)
302303
c.Check(com.Timestamp, chk.Equals, time.Date(2019, time.March, 15, 18, 1, 3, 0, time.UTC))
303-
c.Check(com.Parent, chk.Equals, "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb")
304+
c.Check(com.Parent, chk.Equals, "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941")
304305
c.Check(com.OtherParents, chk.IsNil)
305306
c.Check(com.CommitterName, chk.Equals, "Some One")
306-
c.Check(com.CommitterEmail, chk.Equals, "someone@example.org")
307-
c.Check(com.ID, chk.Equals, "9c4eab0f96134063f856fc48604f49c7c1e225a79f3eebc4e226dc01b4cfe9bc")
307+
c.Check(com.CommitterEmail, chk.Equals, "default@docker-dev.dbhub.io")
308+
c.Check(com.ID, chk.Equals, "70815d687cfc614b23dfb2f66f8fa0a8cb7bad199e05d4142db883690eefeba5")
308309
c.Check(com.Tree.Entries[0].EntryType, chk.Equals, dbTreeEntryType(DATABASE))
309310
c.Check(com.Tree.Entries[0].LastModified.UTC(), chk.Equals, time.Date(2019, time.March, 15, 18, 1, 2, 0, time.UTC))
310311
c.Check(com.Tree.Entries[0].LicenceSHA, chk.Equals, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") // e3b... is the SHA256 for the "Not specified" licence option
@@ -327,7 +328,7 @@ func (s *DioSuite) Test0020_Commit2(c *chk.C) {
327328
// Verify the branch info
328329
br, ok := meta.Branches["master"]
329330
c.Assert(ok, chk.Equals, true)
330-
c.Check(br.Commit, chk.Equals, "9c4eab0f96134063f856fc48604f49c7c1e225a79f3eebc4e226dc01b4cfe9bc")
331+
c.Check(br.Commit, chk.Equals, "70815d687cfc614b23dfb2f66f8fa0a8cb7bad199e05d4142db883690eefeba5")
331332
c.Check(br.CommitCount, chk.Equals, 2)
332333
c.Check(br.Description, chk.Equals, "")
333334

@@ -350,7 +351,7 @@ func (s *DioSuite) Test0030_BranchActiveGet(c *chk.C) {
350351
func (s *DioSuite) Test0040_BranchCreate(c *chk.C) {
351352
// Create a new branch
352353
branchCreateBranch = "branchtwo"
353-
branchCreateCommit = "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb"
354+
branchCreateCommit = "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941"
354355
branchCreateMsg = "A new branch"
355356
err := branchCreate([]string{s.dbName})
356357
c.Assert(err, chk.IsNil)
@@ -360,7 +361,7 @@ func (s *DioSuite) Test0040_BranchCreate(c *chk.C) {
360361
c.Assert(err, chk.IsNil)
361362
br, ok := meta.Branches["branchtwo"]
362363
c.Assert(ok, chk.Equals, true)
363-
c.Check(br.Commit, chk.Equals, "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb")
364+
c.Check(br.Commit, chk.Equals, "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941")
364365
c.Check(br.CommitCount, chk.Equals, 1)
365366
c.Check(br.Description, chk.Equals, "A new branch")
366367

@@ -468,13 +469,13 @@ func (s *DioSuite) Test0100_BranchRevert(c *chk.C) {
468469
c.Assert(err, chk.IsNil)
469470
br, ok := meta.Branches["master"]
470471
c.Assert(ok, chk.Equals, true)
471-
c.Check(br.Commit, chk.Equals, "9c4eab0f96134063f856fc48604f49c7c1e225a79f3eebc4e226dc01b4cfe9bc")
472+
c.Check(br.Commit, chk.Equals, "70815d687cfc614b23dfb2f66f8fa0a8cb7bad199e05d4142db883690eefeba5")
472473
c.Check(br.CommitCount, chk.Equals, 2)
473474
c.Check(br.Description, chk.Equals, "")
474475

475476
// Revert the master branch back to the original commit
476477
branchRevertBranch = "master"
477-
branchRevertCommit = "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb"
478+
branchRevertCommit = "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941"
478479
err = branchRevert([]string{s.dbName})
479480
c.Assert(err, chk.IsNil)
480481

@@ -483,7 +484,7 @@ func (s *DioSuite) Test0100_BranchRevert(c *chk.C) {
483484
c.Assert(err, chk.IsNil)
484485
br, ok = meta.Branches["master"]
485486
c.Assert(ok, chk.Equals, true)
486-
c.Check(br.Commit, chk.Equals, "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb")
487+
c.Check(br.Commit, chk.Equals, "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941")
487488
c.Check(br.CommitCount, chk.Equals, 1)
488489
c.Check(br.Description, chk.Equals, "")
489490

@@ -546,7 +547,7 @@ func (s *DioSuite) Test0130_TagCreate(c *chk.C) {
546547
c.Assert(ok, chk.Equals, false)
547548

548549
// Create the tag
549-
tagCreateCommit = "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb"
550+
tagCreateCommit = "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941"
550551
tagCreateDate = "2019-03-15T18:01:05Z"
551552
tagCreateEmail = "sometagger@example.org"
552553
tagCreateMsg = "This is a test tag"
@@ -622,7 +623,7 @@ func (s *DioSuite) Test0160_ReleaseCreate(c *chk.C) {
622623
c.Assert(ok, chk.Equals, false)
623624

624625
// Create the release
625-
releaseCreateCommit = "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb"
626+
releaseCreateCommit = "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941"
626627
releaseCreateCreatorEmail = "somereleaser@example.org"
627628
releaseCreateCreatorName = "A test releaser"
628629
releaseCreateMsg = "This is a test release"
@@ -701,7 +702,7 @@ func (s *DioSuite) Test0190_Log(c *chk.C) {
701702
l := strings.TrimSpace(lines.Text())
702703
if strings.HasPrefix(l, "*") {
703704
p := strings.Split(lines.Text(), ":")
704-
if len(p) >= 2 && strings.TrimSpace(p[1]) == "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb" {
705+
if len(p) >= 2 && strings.TrimSpace(p[1]) == "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941" {
705706
c.Check(p, chk.HasLen, 2)
706707
comFound = true
707708
}
@@ -1012,7 +1013,7 @@ func (s *DioSuite) Test0280_PullRemote(c *chk.C) {
10121013

10131014
// Grab the database from our test server
10141015
pullCmdBranch = ""
1015-
pullCmdCommit = "eba04c5fe44ec4545c098d092f0231ed672949b3c93651821d3f1102c56e85eb"
1016+
pullCmdCommit = "9a78d0c8c13c0442eb24367f3561d0cbb5676100bd69d147ec3bde4cdbaefa49"
10161017
*pullForce = true
10171018
err = pull([]string{newDB})
10181019
c.Assert(err, chk.IsNil)
@@ -1149,7 +1150,7 @@ func (s *DioSuite) Test0320_PushOldLocalMetadataDBConflict(c *chk.C) {
11491150

11501151
// Revert back to the original commit
11511152
newDB := "19kBv3.sqlite"
1152-
pullCmdCommit = "c9a3e3bd641ca17a79a02cc07cc2ecd0c92a89a5437cf3b96221d57575a6f79f"
1153+
pullCmdCommit = "601e78fb16a715e37e86fc57ba3415e2684481cffea0455eb3463dc086e22177"
11531154
*pullForce = true
11541155
err := pull([]string{newDB})
11551156
c.Assert(err, chk.IsNil)
@@ -1177,8 +1178,8 @@ func mockGetLicences() (map[string]licenceEntry, error) {
11771178
func mockRetrieveMetadata(db string) (meta metaData, onCloud bool, err error) {
11781179
meta.Branches = make(map[string]branchEntry)
11791180
meta.Commits = make(map[string]commitEntry)
1180-
meta.Commits["485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb"] = commitEntry{
1181-
ID: "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb",
1181+
meta.Commits["59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941"] = commitEntry{
1182+
ID: "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941",
11821183
CommitterEmail: "someone@example.org",
11831184
CommitterName: "Some One",
11841185
AuthorEmail: "testdefault@dbhub.io",
@@ -1198,7 +1199,7 @@ func mockRetrieveMetadata(db string) (meta metaData, onCloud bool, err error) {
11981199
},
11991200
}
12001201
meta.Branches["master"] = branchEntry{
1201-
Commit: "485ca5b2014c1520e7952ad97fed0a8024349b43cea7711a6c98706c3d7e55cb",
1202+
Commit: "59b72b78cb83bdba371438cb36950fe007265445a63068ae5586c9cc19203941",
12021203
CommitCount: 1,
12031204
Description: "",
12041205
}
@@ -1363,7 +1364,7 @@ func mockServerNewDBPushHandler(w http.ResponseWriter, r *http.Request) {
13631364
"commit": "",
13641365
"commitmsg": "Test message",
13651366
"committername": "Some One",
1366-
"committeremail": "someone@example.org",
1367+
"committeremail": "default@docker-dev.dbhub.io",
13671368
"dbshasum": "e8cab91dec32b3990b427b28380e4e052288054f99c4894742f07dee0c924efd",
13681369
"lastmodified": time.Date(2019, time.March, 15, 18, 2, 0, 0, time.UTC).Format(time.RFC3339),
13691370
"licence": "",

cmd/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ func init() {
125125
RootCAs: ourCAPool,
126126
}
127127

128-
// Extract the username and server from the TLS certificate
129-
certUser, _, err = getUserAndServer()
128+
// Extract the username and email from the TLS certificate
129+
var email string
130+
certUser, email, _, err = getUserAndServer()
130131
if err != nil {
131132
fmt.Println(err)
132133
}
134+
viper.Set("user.email", email)
133135
}

cmd/shared.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ var getLicences = func() (list map[string]licenceEntry, err error) {
214214
}
215215

216216
// getUserAndServer() returns the user name and server from a DBHub.io client certificate
217-
func getUserAndServer() (userAcc string, certServer string, err error) {
217+
func getUserAndServer() (userAcc string, email string, certServer string, err error) {
218218
if numCerts := len(TLSConfig.Certificates); numCerts == 0 {
219219
err = errors.New("No client certificates installed. Can't proceed.")
220220
return
@@ -228,14 +228,14 @@ func getUserAndServer() (userAcc string, certServer string, err error) {
228228
return
229229
}
230230

231-
// Extract the account name and associated server from the certificate
232-
cn := cert.Subject.CommonName
233-
if cn == "" {
231+
// Extract the account name, email address, and associated server from the certificate
232+
email = cert.Subject.CommonName
233+
if email == "" {
234234
// The common name field is empty in the client cert. Can't proceed.
235235
err = errors.New("Common name is blank in client certificate")
236236
return
237237
}
238-
s := strings.Split(cn, "@")
238+
s := strings.Split(email, "@")
239239
if len(s) < 2 {
240240
err = errors.New("Missing information in client certificate")
241241
return
@@ -247,7 +247,6 @@ func getUserAndServer() (userAcc string, certServer string, err error) {
247247
err = errors.New("Missing information in client certificate")
248248
return
249249
}
250-
251250
return
252251
}
253252

0 commit comments

Comments
 (0)