1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 03:38:43 +00:00

Add unit tests for OAuth2 in ScrapeConfig ()

*  add unit testcases for oauth2 in scrapeconfig CRD
This commit is contained in:
Nutmos 2024-12-20 00:59:33 +08:00 committed by GitHub
parent cc325a0369
commit 449b19e065
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 110 additions and 0 deletions

View file

@ -6358,6 +6358,64 @@ func TestScrapeConfigSpecConfig(t *testing.T) {
},
golden: "ScrapeConfigSpecConfig_EnableHTTP2_False.golden",
},
{
name: "config_oauth",
version: "v2.27.0",
scSpec: monitoringv1alpha1.ScrapeConfigSpec{
OAuth2: &monitoringv1.OAuth2{
ClientID: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "oauth2",
},
Key: "client_id",
},
},
ClientSecret: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "oauth2",
},
Key: "client_secret",
},
TokenURL: "http://test.url",
Scopes: []string{"scope 1", "scope 2"},
EndpointParams: map[string]string{
"param1": "value1",
"param2": "value2",
},
},
},
golden: "ScrapeConfigSpecConfig_WithOAuth.golden",
},
{
name: "config_oauth_unsupported",
version: "v2.26.0",
scSpec: monitoringv1alpha1.ScrapeConfigSpec{
OAuth2: &monitoringv1.OAuth2{
ClientID: monitoringv1.SecretOrConfigMap{
ConfigMap: &v1.ConfigMapKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "oauth2",
},
Key: "client_id",
},
},
ClientSecret: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "oauth2",
},
Key: "client_secret",
},
TokenURL: "http://test.url",
Scopes: []string{"scope 1", "scope 2"},
EndpointParams: map[string]string{
"param1": "value1",
"param2": "value2",
},
},
},
golden: "ScrapeConfigSpecConfig_WithOAuth_Unsupported.golden",
},
} {
t.Run(tc.name, func(t *testing.T) {
scs := map[string]*monitoringv1alpha1.ScrapeConfig{
@ -6415,6 +6473,24 @@ func TestScrapeConfigSpecConfig(t *testing.T) {
"http-sd-key": []byte("http-sd-secret"),
},
},
&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "oauth2",
Namespace: "default",
},
Data: map[string]string{
"client_id": "client-id",
},
},
&v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "oauth2",
Namespace: "default",
},
Data: map[string][]byte{
"client_secret": []byte("client-secret"),
},
},
)
cfg, err := cg.GenerateServerConfiguration(

View file

@ -0,0 +1,22 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: scrapeConfig/default/testscrapeconfig1
oauth2:
client_id: client-id
client_secret: client-secret
token_url: http://test.url
scopes:
- scope 1
- scope 2
endpoint_params:
param1: value1
param2: value2
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name

View file

@ -0,0 +1,12 @@
global:
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
evaluation_interval: 30s
scrape_configs:
- job_name: scrapeConfig/default/testscrapeconfig1
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name