74 lines
2.3 KiB
Go
74 lines
2.3 KiB
Go
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice appear in all copies.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
package connector_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.probo.inc/probo/pkg/connector"
|
|
)
|
|
|
|
func TestDatadogAuthorizeURL(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got, err := connector.DatadogAuthorizeURL("US3")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "https://us3.datadoghq.com/oauth2/v1/authorize", got)
|
|
|
|
got, err = connector.DatadogAuthorizeURL("US1")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "https://app.datadoghq.com/oauth2/v1/authorize", got)
|
|
|
|
_, err = connector.DatadogAuthorizeURL("BOGUS")
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestDatadogTokenURL(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got, err := connector.DatadogTokenURL("us3.datadoghq.com")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "https://api.us3.datadoghq.com/oauth2/v1/token", got)
|
|
|
|
got, err = connector.DatadogTokenURL("datadoghq.eu")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "https://api.datadoghq.eu/oauth2/v1/token", got)
|
|
|
|
_, err = connector.DatadogTokenURL("evil.example.com")
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestIsValidDatadogDomain(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.True(t, connector.IsValidDatadogDomain("datadoghq.com"))
|
|
assert.True(t, connector.IsValidDatadogDomain("ddog-gov.com"))
|
|
assert.False(t, connector.IsValidDatadogDomain("attacker.datadoghq.com.evil.com"))
|
|
assert.False(t, connector.IsValidDatadogDomain(""))
|
|
}
|
|
|
|
func TestDatadogSiteForDomain(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
site, ok := connector.DatadogSiteForDomain("us5.datadoghq.com")
|
|
require.True(t, ok)
|
|
assert.Equal(t, "US5", site)
|
|
|
|
_, ok = connector.DatadogSiteForDomain("nope.com")
|
|
assert.False(t, ok)
|
|
}
|