Plugins: Modify interface for plugin validations to allow taking PDC into account (#96089)
* Request interceptor: Do not block PDC * Apply change after feedback received * Add test * Check if secure socks proxy configured for the instance * Apply suggestions from code review * Add dedicated service for datasource request URL validation (#99179) --------- Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
This commit is contained in:
co-authored by
Will Browne
parent
33a53d170b
commit
d192a44469
@@ -70,6 +70,16 @@ type DataSource struct {
|
||||
|
||||
Created time.Time `json:"created,omitempty"`
|
||||
Updated time.Time `json:"updated,omitempty"`
|
||||
|
||||
isSecureSocksDSProxyEnabled *bool `xorm:"-"`
|
||||
}
|
||||
|
||||
func (ds *DataSource) IsSecureSocksDSProxyEnabled() bool {
|
||||
if ds.isSecureSocksDSProxyEnabled == nil {
|
||||
enabled := ds.JsonData != nil && ds.JsonData.Get("enableSecureSocksProxy").MustBool(false)
|
||||
ds.isSecureSocksDSProxyEnabled = &enabled
|
||||
}
|
||||
return *ds.isSecureSocksDSProxyEnabled
|
||||
}
|
||||
|
||||
type TeamHTTPHeadersJSONData struct {
|
||||
|
||||
@@ -102,3 +102,58 @@ func TestTeamHTTPHeaders(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSecureSocksDSProxyEnabled(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
ds *DataSource
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
desc: "Empty json",
|
||||
ds: &DataSource{
|
||||
JsonData: simplejson.New(),
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
desc: "Json with enableSecureSocksProxy",
|
||||
ds: &DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"enableSecureSocksProxy": true,
|
||||
}),
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
desc: "Json with string enableSecureSocksProxy",
|
||||
ds: &DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"enableSecureSocksProxy": "true",
|
||||
}),
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
desc: "Json with enableSecureSocksProxy false",
|
||||
ds: &DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"enableSecureSocksProxy": false,
|
||||
}),
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
desc: "Json with no json data",
|
||||
ds: &DataSource{},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
actual := tc.ds.IsSecureSocksDSProxyEnabled()
|
||||
assert.Equal(t, tc.want, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -745,7 +745,7 @@ func (s *Service) httpClientOptions(ctx context.Context, ds *datasources.DataSou
|
||||
}
|
||||
}
|
||||
|
||||
if ds.JsonData != nil && ds.JsonData.Get("enableSecureSocksProxy").MustBool(false) {
|
||||
if ds.IsSecureSocksDSProxyEnabled() {
|
||||
proxyOpts := &sdkproxy.Options{
|
||||
Enabled: true,
|
||||
Auth: &sdkproxy.AuthOptions{
|
||||
|
||||
Reference in New Issue
Block a user