forked from Silverfish/proton-bridge
User Agent do not contain bridge version, only client in format
This commit is contained in:
committed by
James Houlahan
parent
1d49a484a8
commit
984b28e8f9
@ -526,14 +526,18 @@ func (b *Bridge) GetCurrentClient() string {
|
||||
func (b *Bridge) SetCurrentClient(clientName, clientVersion string) {
|
||||
b.userAgentClientName = clientName
|
||||
b.userAgentClientVersion = clientVersion
|
||||
b.updateCurrentUserAgent()
|
||||
b.updateUserAgent()
|
||||
}
|
||||
|
||||
// SetCurrentOS updates OS and sets the user agent on pmapi. By default we use
|
||||
// `runtime.GOOS`, but this can be overridden in case of better detection.
|
||||
func (b *Bridge) SetCurrentOS(os string) {
|
||||
b.userAgentOS = os
|
||||
b.updateCurrentUserAgent()
|
||||
b.updateUserAgent()
|
||||
}
|
||||
|
||||
func (b *Bridge) updateUserAgent() {
|
||||
b.clientManager.SetUserAgent(b.userAgentClientName, b.userAgentClientVersion, b.userAgentOS)
|
||||
}
|
||||
|
||||
// GetIMAPUpdatesChannel sets the channel on which idle events should be sent.
|
||||
@ -568,10 +572,6 @@ func (b *Bridge) StopWatchers() {
|
||||
close(b.stopAll)
|
||||
}
|
||||
|
||||
func (b *Bridge) updateCurrentUserAgent() {
|
||||
UpdateCurrentUserAgent(b.config.GetVersion(), b.userAgentOS, b.userAgentClientName, b.userAgentClientVersion)
|
||||
}
|
||||
|
||||
// hasUser returns whether the bridge currently has a user with ID `id`.
|
||||
func (b *Bridge) hasUser(id string) (user *User, ok bool) {
|
||||
for _, u := range b.users {
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
// Copyright (c) 2020 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package bridge
|
||||
|
||||
// IsAuthorized returns whether the user has received an Auth from the API yet.
|
||||
|
||||
@ -5,11 +5,10 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
credentials "github.com/ProtonMail/proton-bridge/internal/bridge/credentials"
|
||||
pmapi "github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockConfiger is a mock of Configer interface
|
||||
@ -320,6 +319,18 @@ func (mr *MockClientManagerMockRecorder) GetClient(arg0 interface{}) *gomock.Cal
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetClient", reflect.TypeOf((*MockClientManager)(nil).GetClient), arg0)
|
||||
}
|
||||
|
||||
// SetUserAgent mocks base method
|
||||
func (m *MockClientManager) SetUserAgent(arg0, arg1, arg2 string) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "SetUserAgent", arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// SetUserAgent indicates an expected call of SetUserAgent
|
||||
func (mr *MockClientManagerMockRecorder) SetUserAgent(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUserAgent", reflect.TypeOf((*MockClientManager)(nil).SetUserAgent), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// MockCredentialsStorer is a mock of CredentialsStorer interface
|
||||
type MockCredentialsStorer struct {
|
||||
ctrl *gomock.Controller
|
||||
|
||||
@ -60,4 +60,5 @@ type ClientManager interface {
|
||||
DisallowProxy()
|
||||
GetAuthUpdateChannel() chan pmapi.ClientAuth
|
||||
CheckConnection() error
|
||||
SetUserAgent(clientName, clientVersion, os string)
|
||||
}
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
// Copyright (c) 2020 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
)
|
||||
|
||||
// UpdateCurrentUserAgent updates user agent on pmapi so each request has this
|
||||
// information in headers for statistic purposes.
|
||||
func UpdateCurrentUserAgent(bridgeVersion, os, clientName, clientVersion string) {
|
||||
if os == "" {
|
||||
os = runtime.GOOS
|
||||
}
|
||||
mailClient := "unknown client"
|
||||
if clientName != "" {
|
||||
mailClient = clientName
|
||||
if clientVersion != "" {
|
||||
mailClient += "/" + clientVersion
|
||||
}
|
||||
}
|
||||
pmapi.CurrentUserAgent = fmt.Sprintf("Bridge/%s (%s; %s)", bridgeVersion, os, mailClient)
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2020 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUpdateCurrentUserAgentGOOS(t *testing.T) {
|
||||
UpdateCurrentUserAgent("ver", "", "", "")
|
||||
assert.Equal(t, "Bridge/ver ("+runtime.GOOS+"; unknown client)", pmapi.CurrentUserAgent)
|
||||
}
|
||||
|
||||
func TestUpdateCurrentUserAgentOS(t *testing.T) {
|
||||
UpdateCurrentUserAgent("ver", "os", "", "")
|
||||
assert.Equal(t, "Bridge/ver (os; unknown client)", pmapi.CurrentUserAgent)
|
||||
}
|
||||
|
||||
func TestUpdateCurrentUserAgentClientVer(t *testing.T) {
|
||||
UpdateCurrentUserAgent("ver", "os", "", "cver")
|
||||
assert.Equal(t, "Bridge/ver (os; unknown client)", pmapi.CurrentUserAgent)
|
||||
}
|
||||
|
||||
func TestUpdateCurrentUserAgentClientName(t *testing.T) {
|
||||
UpdateCurrentUserAgent("ver", "os", "mail", "")
|
||||
assert.Equal(t, "Bridge/ver (os; mail)", pmapi.CurrentUserAgent)
|
||||
}
|
||||
|
||||
func TestUpdateCurrentUserAgentClientNameAndVersion(t *testing.T) {
|
||||
UpdateCurrentUserAgent("ver", "os", "mail", "cver")
|
||||
assert.Equal(t, "Bridge/ver (os; mail/cver)", pmapi.CurrentUserAgent)
|
||||
}
|
||||
Reference in New Issue
Block a user