@@ -920,6 +920,68 @@ func TestArtifactHandler_GlobArtifacts(t *testing.T) {
920920 }
921921}
922922
923+ func TestArtifactHandler_UploadFromSandbox (t * testing.T ) {
924+ gin .SetMode (gin .TestMode )
925+
926+ t .Run ("returns 404 when disk belongs to different project" , func (t * testing.T ) {
927+ mockService := new (MockArtifactService )
928+ mockDiskRepo := new (MockDiskRepo )
929+
930+ projectID := uuid .New ()
931+ diskID := uuid .New ()
932+
933+ // Disk not found for this project (IDOR check)
934+ mockDiskRepo .On ("GetByProjectAndID" , mock .Anything , projectID , diskID ).
935+ Return (nil , fmt .Errorf ("record not found" ))
936+
937+ handler := NewArtifactHandler (mockService , mockDiskRepo , createDefaultTestConfig (), nil , nil )
938+
939+ w := httptest .NewRecorder ()
940+ c , _ := gin .CreateTestContext (w )
941+ c .Set ("project" , & model.Project {ID : projectID })
942+
943+ body := `{"sandbox_id":"` + uuid .New ().String () + `","sandbox_path":"/tmp","sandbox_filename":"test.txt","file_path":"/"}`
944+ c .Request = httptest .NewRequest ("POST" , "/disk/" + diskID .String ()+ "/artifact/upload_from_sandbox" , bytes .NewBufferString (body ))
945+ c .Request .Header .Set ("Content-Type" , "application/json" )
946+ c .Params = gin.Params {{Key : "disk_id" , Value : diskID .String ()}}
947+
948+ handler .UploadFromSandbox (c )
949+
950+ assert .Equal (t , http .StatusNotFound , w .Code )
951+ mockService .AssertNotCalled (t , "Create" )
952+ mockDiskRepo .AssertExpectations (t )
953+ })
954+
955+ t .Run ("returns 400 for invalid request body" , func (t * testing.T ) {
956+ mockService := new (MockArtifactService )
957+ mockDiskRepo := new (MockDiskRepo )
958+
959+ projectID := uuid .New ()
960+ diskID := uuid .New ()
961+
962+ // Disk found for this project
963+ mockDiskRepo .On ("GetByProjectAndID" , mock .Anything , projectID , diskID ).
964+ Return (& model.Disk {ID : diskID , ProjectID : projectID }, nil )
965+
966+ handler := NewArtifactHandler (mockService , mockDiskRepo , createDefaultTestConfig (), nil , nil )
967+
968+ w := httptest .NewRecorder ()
969+ c , _ := gin .CreateTestContext (w )
970+ c .Set ("project" , & model.Project {ID : projectID })
971+
972+ // Empty JSON body — missing required fields
973+ c .Request = httptest .NewRequest ("POST" , "/disk/" + diskID .String ()+ "/artifact/upload_from_sandbox" , bytes .NewBufferString (`{}` ))
974+ c .Request .Header .Set ("Content-Type" , "application/json" )
975+ c .Params = gin.Params {{Key : "disk_id" , Value : diskID .String ()}}
976+
977+ handler .UploadFromSandbox (c )
978+
979+ assert .Equal (t , http .StatusBadRequest , w .Code )
980+ mockService .AssertNotCalled (t , "Create" )
981+ mockDiskRepo .AssertExpectations (t )
982+ })
983+ }
984+
923985func TestArtifactHandler_DownloadArtifact (t * testing.T ) {
924986 gin .SetMode (gin .TestMode )
925987
0 commit comments