MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / callback_server_rejects_wrong_code

Function callback_server_rejects_wrong_code

crates/openshell-cli/src/auth.rs:681–725  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

679
680 #[tokio::test]
681 async fn callback_server_rejects_wrong_code() {
682 let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
683 let addr = listener.local_addr().unwrap();
684 let (tx, rx) = oneshot::channel();
685
686 tokio::spawn(run_callback_server(
687 listener,
688 tx,
689 "ABC-1234".to_string(),
690 TEST_GATEWAY.to_string(),
691 ));
692
693 let mut stream = tokio::net::TcpStream::connect(addr).await.unwrap();
694 let body = r#"{"token":"test-jwt","code":"WRONG-CODE"}"#;
695 let request = format!(
696 "POST /callback HTTP/1.1\r\n\
697 Host: 127.0.0.1\r\n\
698 Origin: {TEST_GATEWAY}\r\n\
699 Content-Type: application/json\r\n\
700 Content-Length: {}\r\n\r\n\
701 {}",
702 body.len(),
703 body,
704 );
705 stream.write_all(request.as_bytes()).await.unwrap();
706
707 // Read the response — should be 403.
708 let mut buf = vec![0u8; 4096];
709 let n = stream.read(&mut buf).await.unwrap();
710 let response = String::from_utf8_lossy(&buf[..n]);
711 assert!(
712 response.contains("403 Forbidden"),
713 "wrong code should return 403:\n{response}"
714 );
715 assert!(
716 response.contains("confirmation code mismatch"),
717 "should explain the error:\n{response}"
718 );
719
720 // Token channel should not receive a value.
721 assert!(
722 rx.await.is_err(),
723 "token channel should not receive a value with wrong code"
724 );
725 }
726
727 #[tokio::test]
728 async fn callback_server_rejects_missing_fields() {

Callers

nothing calls this directly

Calls 4

run_callback_serverFunction · 0.85
connectFunction · 0.85
spawnFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected