Skip to content

Commit 06537d2

Browse files
committed
Add a test for log masking
This is only a basic test that the masking is in fact being applied to variables marked as masked. This is not a test of the functionality of the masking crate, only of its integration into this crate.
1 parent 76a0ce3 commit 06537d2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

gitlab-runner/tests/integration.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,53 @@ async fn job_log() {
412412
.await;
413413
}
414414

415+
#[tokio::test]
416+
async fn job_mask_log() {
417+
let mock = GitlabRunnerMock::start().await;
418+
let job = {
419+
let mut b = mock.job_builder("log".to_string());
420+
b.add_variable("SECRET".to_string(), "$ecret".to_string(), false, true);
421+
b.add_step(
422+
MockJobStepName::Script,
423+
vec!["dummy".to_string()],
424+
3600,
425+
MockJobStepWhen::OnSuccess,
426+
false,
427+
);
428+
b.build()
429+
};
430+
mock.enqueue_job(job.clone());
431+
432+
let dir = tempfile::tempdir().unwrap();
433+
let (mut runner, layer) = Runner::new_with_layer(
434+
mock.uri(),
435+
mock.runner_token().to_string(),
436+
dir.path().to_path_buf(),
437+
);
438+
439+
let subscriber = Registry::default().with(layer);
440+
async {
441+
tracing::info!("TEST");
442+
let got_job = runner
443+
.request_job(|job| async move {
444+
tracing::info!("TEST1234");
445+
outputln!("aa-$ecret");
446+
job.trace("bb$ec");
447+
outputln!("retxyz");
448+
SimpleRun::dummy(Ok(())).await
449+
})
450+
.with_current_subscriber()
451+
.await
452+
.unwrap();
453+
assert!(got_job);
454+
runner.wait_for_space(1).await;
455+
assert_eq!(MockJobState::Success, job.state());
456+
assert_eq!(b"aa-[MASKED]\nbb[MASKED]xyz\n", job.log().as_slice());
457+
}
458+
.with_subscriber(subscriber)
459+
.await;
460+
}
461+
415462
#[tokio::test]
416463
async fn job_steps() {
417464
let mock = GitlabRunnerMock::start().await;

0 commit comments

Comments
 (0)