Skip to content

Commit

Permalink
test: update otel integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Sestito <[email protected]>
  • Loading branch information
fabriziosestito committed Dec 9, 2024
1 parent a20b8a9 commit 2e6f873
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub(crate) fn default_test_config() -> Config {
log_fmt: "json".to_owned(),
log_no_color: false,
otlp_endpoint: None,
otlp_tls_config: Default::default(),
daemon: false,
daemon_pid_file: "policy_server.pid".to_owned(),
daemon_stdout_file: None,
Expand Down
21 changes: 21 additions & 0 deletions tests/data/ca.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIUelYKxNE+hEOUDY9vF4oSJ567zzEwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDEyMDkxNzA2NTVaFw0yOTEy
MDgxNzA2NTVaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQDb2HiIf1RaWJqua83AedtjkGe9x8TLy1cXE/W6w4Ia
FYtufzNGUZpBmrv6MmUJNB3RRxtYTT2TTwSsAykxXaVtNle48XYOE4mBJOroNa65
F8bSe64kn10bHwy3QM5CxcTLpJoFfB+fyuYUoYCeLriZ3fZU69gZSsbluIJmnH81
gee+xO/Pue6mPUbZhOPYd6K3+Q5Vw1LJnLO5aNa5xTbAcko9tizmSxTmfRDGlzgx
6uO3tzsrvo9Hev6Ygpce/zWddr64MRX72E5ToVBfvK8EbpPSwA6NQtaJtv9UXUQL
JShzq4kud2e949unEg3ZAMZTus+3DGUmLaai79XkG3QZAgMBAAGjUzBRMB0GA1Ud
DgQWBBTLjPkOsIvZ8FUnWePvpmxDyEYhPDAfBgNVHSMEGDAWgBTLjPkOsIvZ8FUn
WePvpmxDyEYhPDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQA4
3xhMYZ9/0AqEHNuc/yWIvUfsKryvLMIJ/oU/Ko1ixXdPH+49sUw+aSBEjKOJVIyf
2jTKHvFUzQOhA+939O+Vesf5Avitc7V/USUB6smgYVE9+0mLwD8koq7punNEUy8N
nXBxfncl1/5C8W2pZg+El3GWL6Z6BqyhWXNB7dWvVaJO51g50Kti8Re7NE6TbNtQ
8Znsp3W6MJg6n19Tl7ZJiamzHtojCKrqc7a69rxln92W41K2XTTBjJL4eHB/Ph4Q
v+kUzFgbhzoI94ix1wKLu7U4EF11IA1R0i5lJ9vHo6YYyJB40/w+J5bG6dGOybBE
+uBiBir2rDQ6R410yfqG
-----END CERTIFICATE-----
24 changes: 24 additions & 0 deletions tests/data/client-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID8DCCAdigAwIBAgIUOeERiSqnvvahNnd5dWIZdbYHDSYwDQYJKoZIhvcNAQEL
BQAwDzENMAsGA1UEAwwETXlDQTAeFw0yNDEyMDkxNTM0NTZaFw0yNTEyMDkxNTM0
NTZaMBExDzANBgNVBAMMBmNsaWVudDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBALj5LVWAAq5ALh/rPO3xK+DgVT/pYSoTRJlT8UAGMVJonX3mraXVDXAz
TfS29r9xQJwZjbfkxbrBwR4RsDugkOTpoxlbngYFsKn4Yq0Kyuc3maEguVyVWWQX
GEzzhoe6ivOnCcNJNwf2M+4ZZhUQ8+m43eYg2mtJIYqEv7/6tH7JuprJ28iuypoL
qEiRY5/d70wYWIpMCV3LnavUJvH6OB23cfhQ1NYyjylOOlk7mlVFfONNsdg26NTV
xVVt1XWrjl6QieTnwwl8D0JeK7A3FX5d7n1tVVTLYMBs7UwBeEH33ELsuGBhPv+r
t1g6Sp3380lrFFwvVw+2b3rkF9VBdEsCAwEAAaNCMEAwHQYDVR0OBBYEFKR8DvjY
HIZzQlSS7bPRUfixr7kgMB8GA1UdIwQYMBaAFM++ZOTaTt+mh5E7goRMwKw0/5gr
MA0GCSqGSIb3DQEBCwUAA4ICAQCSy6vC0np3eoKDgWGBgsd7khurcCGpaudx5ZjM
bLznfGNR00B5B9zkuBQsCrqSzqFkINnSNz170vH5zBOdD6iTHB4NUizom1cdbet5
zydvbDBah07GjbYluiqjaw56XoAcOzyGSIQTK1ZnS2QNlspzBPHqwBcbFY8qRjvH
AoXV1sGaPJM+szQBY0UQnrwHMLD8PyWuWxJzuZFsDXwxKJHii3wcFUTmwPToZgga
npwNFIEdijT6A13VbN3BQlhQzs5NWolKQXHkzX00wZyBjFucuA0eHqXJR9P/W+n0
3Dd6LXRWL3JDhuffkTPABJ4zcsPHdkL2cf5MDF2PoU925pJ5Tee5MzJU6089MfDA
RMUh0JGzBGuM29dAchY/tWbEcHJC2OWb1PEuy6mAjw4HH3jMAvWQlTroIGf/1hva
mdLPEBxEykIxS/9QbWnvAYuxrW5wQ+mt8wWf3MivCjHGUv7MaWH2pj7WzRB482Pk
yMO6jjnpmVutr3sRyoOo/iVTaTP80tu/3Mysx42L//oOOy4Yp77J6daEJDa25BGy
XI+PrkygXiUe1wtvV1pgUrEQtiZP1nIEELiWXtDrj8wj4ma149fkHpmtFU/AurxT
CMCHi1mcq96tS3XmSU4fkZtUCieqo8bauS04Kp2fgomfUJngdH8KQ7lOCAdXJxsr
WurNfQ==
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions tests/data/client-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSj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rLOf5qAhzFv08wfGyu/0HJyiyPXR2wtwUw0mrUVJrX
q9BfeO3CfDKFrdIkBvWniAf/ztskmxk9lQVVOYkPR+qEQY8+Ueh9pweLAPd3yIr/
paA9TUnd1dHvD6OBq2lY5pqB40LAMfdb8Ibi82yjQerCIHrGb1y78cRhAoGBAJo1
ZRrO3n3PHi6ECXYWax2gmdU0jJ+xQaJtq/9bGbsSpf0KUSv0O/RCh1NdNS+EhJgN
WLQYiTSv9foN3MwGPYLwZkmtKGfUFG2cHgiOkIhohkv71MV7QckHbYfc9r+P3Lib
vjp/8lOmi0PgX7Xr9o3EwoVJXrIme8PWe4hiDwiNAoGASJAsHUQ9LCg3i0mKF/Qp
u0oKi6iW5xSIVSuzazBaqQyM3RAAcymbGbQ1oWMFNDwWkkxpDLOYaBvGkQBk2JXU
5p8EYJZY+KOUgZ+IKt/Ibqbmsl/Z9JxYWhLvKAs4iHjPNr+yIsZ4/RCyss+pNEyb
C+DqJyhNSVGeeMqshLkwRVs=
-----END PRIVATE KEY-----
4 changes: 4 additions & 0 deletions tests/data/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ receivers:
otlp:
protocols:
grpc:
tls:
ca_file: "certs/ca.pem"
cert_file: "certs/server-cert.pem"
key_file: "certs/server-key.pem"

exporters:
file/metrics:
Expand Down
21 changes: 21 additions & 0 deletions tests/data/server-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDezCCAmOgAwIBAgIUCph+VxBXp4p8lHfk1+kfgcrdaHwwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDEyMDkxNzA3MTRaFw0yNTEy
MDkxNzA3MTRaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQDNkhFV13bj/nlDzRg86sJsA57k0ggCDoWAFFbIWnti
nMhZY4BqU6xJ42V7Sqr+RdTdMU5c0xjBX62zf6aEiSebwvrs5tjB6y/00UsZUmCB
WQBkkzDAYPKyoX7euoPnn7BUBxBdbt1ZUWZEuxWHj171QiEt/IAmlJgxkMmaBQf/
PQEXLXAlIohZXcUu+KR7QB5rAB2gYl3bl5iToyP44KgiBMX+nR4N80bJ4mcHPNqR
ZXkdxWCJXb8VPVX3lfbceKc08iD3zhb9dY/tj/8kPOXZOwMQlLdwkY+nGRVmEPnP
AfClVlIPAk6vgz4Vh6evwTXPwNJXBOOwW3of35W8jSBVAgMBAAGjYzBhMB8GA1Ud
IwQYMBaAFMuM+Q6wi9nwVSdZ4++mbEPIRiE8MAkGA1UdEwQCMAAwFAYDVR0RBA0w
C4IJbG9jYWxob3N0MB0GA1UdDgQWBBTWFzOksM1kDCtKtShGTQ2R0TxN3TANBgkq
hkiG9w0BAQsFAAOCAQEA2W9IwSWAiNbPYRa9TqhW+W5nMQVIbcYTzk57GQ04m37W
M7zhd7eGanPtKj3mdr6dp8/3bMp5U98bPaFL04vNHPr8aYv5ODiqHhSwaxvE9hI3
usuIwvfr2+LfIgrwyzxSB3NaRDYxGRkny1zkn0Tk4nyUNw2jXUmP0RkFMiUzHfsw
FS6dHUopSWM/U9NAZviUzMGzHPaEvXfBZavaMSkC7jc0Er8XCxRDssURHOmT0Cky
84pbKGMrTtxuASkIatN09Ou8aWiBv2m+iwd/ck3MFk86mtjKIftXdh2Mhv9U0eH+
1uF/cGTTUl21hsAji4lZHsB90AXC+9lBOEsID8P+zg==
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions tests/data/server-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkq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2j46VqpYe1cVqy
XedJ722f2wKBgGBUdgumZd76bk0kSIUODEvyMk0zLkvgDCafeNrmJlNbJ9YQpIuo
MnQ5A8IQkhK0ixnUf2gxDk6Oc9oFSU+BV+bvtsMjZC4zJt0cISJngVmLE6TC6gpA
J4Tmg38Xx07cObTkVsJ0Z5tobuzu4I80Mj4+PCS5gpIbk2ZAtEZapxAjAoGAb98H
14j4lUyfLCexgdy6tVjVUjPBl87HEx0cTwrgzY5kzbba+sAp/PD+bDXKyUNf68bv
TmrdveRK4wpttCvWyj1rYNKb2hS9ujrd6/Z1VN+iapcG+1umAPA28898LnmFbRyF
E95b7rDEOt2VnoPt6qyWlly7OuvkncWuu3tzLCsCgYBpIIdfH60Mdt9Bp+IKrIJY
3irYyi8TLTWp157ksIsr1orzVHFB8OMKas7EQQTLSxlb7v23OT0r3eL2XRvNOyCr
evKIO+B0bVxxsN+O16ldaElrwLyoZTJolCyMWQuQt3Zigm/VGaZiAD7er0qg6s/4
hjUCBY6dmVTP8l6afx5d/w==
-----END PRIVATE KEY-----
44 changes: 39 additions & 5 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use policy_evaluator::{
admission_response::AdmissionResponseStatus,
policy_fetcher::verify::config::VerificationConfigV1,
};
use policy_server::config::OtlpTlsConfig;
use policy_server::{
api::admission_review::AdmissionReviewResponse,
config::{PolicyMode, PolicyOrPolicyGroup},
Expand Down Expand Up @@ -746,8 +747,18 @@ async fn test_detect_certificate_rotation() {
async fn test_otel() {
setup();

let mut otelc_config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
otelc_config_path.push("tests/data/otel-collector-config.yaml");
let otelc_config_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/otel-collector-config.yaml");

let ca_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/ca.pem");
let server_cert_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/server-cert.pem");
let server_key_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/server-key.pem");
let client_cert_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/client-cert.pem");
let client_key_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/client-key.pem");

let metrics_output_file = NamedTempFile::new().unwrap();
let metrics_output_file_path = metrics_output_file.path();
Expand All @@ -757,7 +768,7 @@ async fn test_otel() {

let permissions = Permissions::from_mode(0o666);
set_permissions(metrics_output_file_path, permissions.clone()).unwrap();
set_permissions(traces_output_file_path, permissions).unwrap();
set_permissions(traces_output_file_path, permissions.clone()).unwrap();

let otelc = GenericImage::new("otel/opentelemetry-collector", "0.98.0")
.with_wait_for(WaitFor::message_on_stderr("Everything is ready"))
Expand All @@ -773,6 +784,18 @@ async fn test_otel() {
traces_output_file_path.to_str().unwrap(),
"/tmp/traces.json",
))
.with_mount(Mount::bind_mount(
ca_path.to_str().unwrap(),
"/certs/ca.pem",
))
.with_mount(Mount::bind_mount(
server_cert_path.to_str().unwrap(),
"/certs/server-cert.pem",
))
.with_mount(Mount::bind_mount(
server_key_path.to_str().unwrap(),
"/certs/server-key.pem",
))
.with_mapped_port(1337, 4317.into())
.with_cmd(vec!["--config=/etc/otel-collector-config.yaml"])
.with_startup_timeout(Duration::from_secs(30))
Expand All @@ -783,13 +806,24 @@ async fn test_otel() {
let mut config = default_test_config();
config.metrics_enabled = true;
config.log_fmt = "otlp".to_string();
config.otlp_endpoint = Some("http://localhost:1337".to_string());
setup_metrics(config.otlp_endpoint.as_deref()).unwrap();
config.otlp_endpoint = Some("https://localhost:1337".to_string());
config.otlp_tls_config = OtlpTlsConfig {
ca_file: Some(ca_path),
cert_file: Some(client_cert_path),
key_file: Some(client_key_path),
};

setup_metrics(
config.otlp_endpoint.as_deref(),
config.otlp_tls_config.clone(),
)
.unwrap();
setup_tracing(
&config.log_level,
&config.log_fmt,
config.log_no_color,
config.otlp_endpoint.as_deref(),
config.otlp_tls_config.clone(),
)
.unwrap();

Expand Down

0 comments on commit 2e6f873

Please sign in to comment.