@@ -448,3 +448,141 @@ def test_rate_limiters_api_config(test_microvm_with_api):
448448 )
449449 """ Verify the request succeeded """
450450 assert (test_microvm .api_session .is_good_response (response .status_code ))
451+
452+
453+ @pytest .mark .timeout (100 )
454+ def test_api_unknown_fields (test_microvm_with_api ):
455+ """ Tests that requests with unknown fields result in error 400 """
456+
457+ test_microvm = test_microvm_with_api
458+
459+ """ Test invalid field for APILoggerDescription """
460+ """ path -> pth """
461+ response = test_microvm .api_session .put (
462+ test_microvm .logger_url ,
463+ json = {
464+ 'pth' : 'firecracker.log' ,
465+ 'level' : 'Info' ,
466+ 'show_level' : True ,
467+ 'show_log_origin' : True
468+ }
469+ )
470+ assert response .status_code == 400
471+
472+ """ Test invalid field for BootSourceBody """
473+ """ source_type -> source-type """
474+ response = test_microvm .api_session .put (
475+ test_microvm .boot_cfg_url ,
476+ json = {
477+ 'boot_source_id' : 'alinux_kernel' ,
478+ 'source-type' : 'LocalImage' ,
479+ 'local_image' : { 'kernel-image_path' : test_microvm .slot .kernel_file },
480+ }
481+ )
482+ assert response .status_code == 400
483+
484+ """ Test invalid field for LocalImage """
485+ """ kernel_image_path -> kernel-image_path """
486+ response = test_microvm .api_session .put (
487+ test_microvm .boot_cfg_url ,
488+ json = {
489+ 'boot_source_id' : 'alinux_kernel' ,
490+ 'source_type' : 'LocalImage' ,
491+ 'local_image' : { 'kernel-image_path' : test_microvm .slot .kernel_file },
492+ }
493+ )
494+ assert response .status_code == 400
495+
496+ """ Test invalid field for DriveDescription """
497+ """ drive_id -> drive-id """
498+ response = test_microvm .api_session .put (
499+ test_microvm .blk_cfg_url ,
500+ json = {
501+ 'drive-id' : 'root' ,
502+ 'path_on_host' : test_microvm .slot .rootfs_file ,
503+ 'is_root_device' : True ,
504+ 'permissions' : 'rw' ,
505+ 'state' : 'Attached'
506+ }
507+ )
508+ assert response .status_code == 400
509+
510+ """ Test invalid field for MachineConfiguration """
511+ """ vcpu_count -> vcpu-count """
512+ response = test_microvm .api_session .put (
513+ test_microvm .microvm_cfg_url ,
514+ json = { 'vcpu-count' : 4 , 'mem_size_mib' : 256 }
515+ )
516+ assert response .status_code == 400
517+
518+ """ Test invalid field for NetworkInterfaceBody """
519+ """ iface_id -> iface-id """
520+ response = test_microvm .api_session .put (
521+ test_microvm .net_cfg_url ,
522+ json = {
523+ 'iface-id' : 1 ,
524+ 'host_dev_name' : 'vmtap33' ,
525+ 'guest_mac' : '06:00:00:00:00:01' ,
526+ 'state' : 'Attached'
527+ }
528+ )
529+ assert response .status_code == 400
530+
531+ """ Test invalid field for TokenBucketDescription """
532+ """ size -> siz """
533+ response = test_microvm .api_session .put (
534+ test_microvm .net_cfg_url ,
535+ json = {
536+ 'iface_id' : 1 ,
537+ 'host_dev_name' : 'vmtap33' ,
538+ 'guest_mac' : '06:00:00:00:00:01' ,
539+ 'state' : 'Attached' ,
540+ 'rx_rate_limiter' : {
541+ 'bandwidth' : { 'siz' : 1000000 , 'refill_time' : 1000 }
542+ }
543+ }
544+ )
545+ assert response .status_code == 400
546+
547+ """ Test invalid field for RateLimiterDescription """
548+ """ ops -> op """
549+ response = test_microvm .api_session .put (
550+ test_microvm .net_cfg_url ,
551+ json = {
552+ 'iface_id' : 1 ,
553+ 'host_dev_name' : 'vmtap33' ,
554+ 'guest_mac' : '06:00:00:00:00:01' ,
555+ 'state' : 'Attached' ,
556+ 'rx_rate_limiter' : {
557+ 'op' : { 'size' : 1000000 , 'refill_time' : 1000 }
558+ }
559+ }
560+ )
561+ assert response .status_code == 400
562+
563+ """ Test invalid field for AsyncRequestBody """
564+ """ action_id -> action-id """
565+ response = test_microvm .api_session .put (
566+ test_microvm .actions_url ,
567+ json = {
568+ 'action_di' : 'start' ,
569+ 'action_type' : 'InstanceStart' ,
570+ }
571+ )
572+ assert response .status_code == 400
573+
574+ """ Test invalid field for InstanceDeviceDetachAction """
575+ """ device_resource_id -> device_resource_di """
576+ response = test_microvm .api_session .put (
577+ test_microvm .actions_url ,
578+ json = {
579+ 'action_id' : 'start3' ,
580+ 'action_type' : 'InstanceStart' ,
581+ 'instance_device_detach_action' : {
582+ 'device_type' : 'Drive' ,
583+ 'device_resource_di' : 1 ,
584+ 'force' : True
585+ }
586+ }
587+ )
588+ assert response .status_code == 400
0 commit comments