Skip to content

Commit

Permalink
development: revert #61 (#73)
Browse files Browse the repository at this point in the history
* Revert "MongoDB 3.6: implement the new wire protocol (#61)"

This reverts commit 90c056c.

* test against 3.6

* update go and mongodb version

  - use last minor version for each major serie of
    mongodb
  - use travis 'go' param instead of eval "$(gimme $GO)"
    as it fails to install correctly last minor version
    ( 1.8.x notation for example)

* test fixes on 3.2.17

also re-enable TestFindIterSnapshot as it was fixed
a long time ago

* fix X509 test

fix TestAuthX509CredRDNConstruction test: need to
create an user with {"username": subject} before
trying to login

* Fix auth test on 3.6-rc3

Make sure that "rs3/127.0.0.1/40031" is elected
at primary.
Create user before running 'addShard' command as
it requires root access
Also add a retry mechanism to make sure that shard
are correctly added
cf https://docs.mongodb.com/manual/tutorial/deploy-shard-cluster/

* update to 3.6.0 stable

* tests: cherry pick missing 3.6+ support changes
  • Loading branch information
domodwyer authored Jan 9, 2018
1 parent a104bfb commit f9be6c5
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 884 deletions.
57 changes: 30 additions & 27 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ func (socket *mongoSocket) Login(cred Credential) error {
return nil
}
}
if socket.dropLogout(cred) {
debugf("Socket %p to %s: login: db=%q user=%q (cached)", socket, socket.addr, cred.Source, cred.Username)
socket.creds = append(socket.creds, cred)
socket.Unlock()
return nil
}
socket.Unlock()

debugf("Socket %p to %s: login: db=%q user=%q", socket, socket.addr, cred.Source, cred.Username)
Expand Down Expand Up @@ -406,50 +412,36 @@ func (socket *mongoSocket) Logout(db string) {
cred, found := socket.dropAuth(db)
if found {
debugf("Socket %p to %s: logout: db=%q (flagged)", socket, socket.addr, db)
socket.Unlock()
err := socket.flushLogout(cred)
if err != nil {
debugf("fail to logout for cred %v; error: %v", cred, err)
}
} else {
socket.Unlock()
socket.logout = append(socket.logout, cred)
}
socket.Unlock()
}

func (socket *mongoSocket) LogoutAll() {
socket.Lock()
if l := len(socket.creds); l > 0 {
credCopy := make([]Credential, l)
copy(credCopy, socket.creds)
socket.creds = socket.creds[0:0]
socket.Unlock()
debugf("Socket %p to %s: logout all (flagged %d)", socket, socket.addr, l)
err := socket.flushLogout(credCopy...)
if err != nil {
debugf("fail to logout for cred %v, error: %v", credCopy, err)
}
} else {
socket.Unlock()
socket.logout = append(socket.logout, socket.creds...)
socket.creds = socket.creds[0:0]
}
socket.Unlock()
}

func (socket *mongoSocket) flushLogout(cred ...Credential) error {
if l := len(cred); l > 0 {
func (socket *mongoSocket) flushLogout() (ops []interface{}) {
socket.Lock()
if l := len(socket.logout); l > 0 {
debugf("Socket %p to %s: logout all (flushing %d)", socket, socket.addr, l)
ops := make([]interface{}, l)
for i := 0; i != l; i++ {
op := queryOp{}
op.query = &logoutCmd{1}
op.collection = cred[i].Source + ".$cmd"
op.collection = socket.logout[i].Source + ".$cmd"
op.limit = -1
ops[i] = &op
}
err := socket.Query(ops...)
if err != nil {
return fmt.Errorf("fail to logout: %v", err)
ops = append(ops, &op)
}
socket.logout = socket.logout[0:0]
}
return nil
socket.Unlock()
return
}

func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
Expand All @@ -462,3 +454,14 @@ func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
}
return cred, false
}

func (socket *mongoSocket) dropLogout(cred Credential) (found bool) {
for i, sockCred := range socket.logout {
if sockCred == cred {
copy(socket.logout[i:], socket.logout[i+1:])
socket.logout = socket.logout[:len(socket.logout)-1]
return true
}
}
return false
}
Loading

0 comments on commit f9be6c5

Please sign in to comment.