@@ -2,7 +2,7 @@ use crate::tests::builders::CrateBuilder;
22use crate :: tests:: util:: { RequestHelper , Response , TestApp } ;
33use anyhow:: anyhow;
44use bytes:: Bytes ;
5- use crates_io_database:: schema:: trustpub_configs_github;
5+ use crates_io_database:: schema:: { emails , trustpub_configs_github} ;
66use crates_io_github:: { GitHubError , GitHubUser , MockGitHubClient } ;
77use diesel:: prelude:: * ;
88use diesel_async:: RunQueryDsl ;
@@ -370,3 +370,38 @@ async fn test_github_error() -> anyhow::Result<()> {
370370
371371 Ok ( ( ) )
372372}
373+
374+ #[ tokio:: test( flavor = "multi_thread" ) ]
375+ async fn test_unverified_email ( ) -> anyhow:: Result < ( ) > {
376+ let ( app, _client, cookie_client) = TestApp :: full ( )
377+ . with_github ( simple_github_mock ( ) )
378+ . with_user ( )
379+ . await ;
380+
381+ let mut conn = app. db_conn ( ) . await ;
382+
383+ diesel:: update ( emails:: table. filter ( emails:: user_id. eq ( cookie_client. as_model ( ) . id ) ) )
384+ . set ( emails:: verified. eq ( false ) )
385+ . execute ( & mut conn)
386+ . await ?;
387+
388+ CrateBuilder :: new ( CRATE_NAME , cookie_client. as_model ( ) . id )
389+ . build ( & mut conn)
390+ . await ?;
391+
392+ let body = serde_json:: to_vec ( & json ! ( {
393+ "github_config" : {
394+ "crate" : CRATE_NAME ,
395+ "repository_owner" : "rust-lang" ,
396+ "repository_name" : "foo-rs" ,
397+ "workflow_filename" : "publish.yml" ,
398+ "environment" : null,
399+ }
400+ } ) ) ?;
401+
402+ let response = cookie_client. put :: < ( ) > ( URL , body) . await ;
403+ assert_eq ! ( response. status( ) , StatusCode :: FORBIDDEN ) ;
404+ assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"You must verify your email address to create a Trusted Publishing config"}]}"# ) ;
405+
406+ Ok ( ( ) )
407+ }
0 commit comments