mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	Fix panic when Vault enters recovery mode, added test (#20418)
* Fix panic when Vault enters recovery mode, added test * Added changelog
This commit is contained in:
		
							
								
								
									
										3
									
								
								changelog/20418.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								changelog/20418.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | ```release-note:bug | ||||||
|  | command/server: fixes panic in Vault server command when running in recovery mode | ||||||
|  | ``` | ||||||
| @@ -457,7 +457,7 @@ func (c *ServerCommand) runRecoveryMode() int { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Update the 'log' related aspects of shared config based on config/env var/cli | 	// Update the 'log' related aspects of shared config based on config/env var/cli | ||||||
| 	c.Flags().applyLogConfigOverrides(config.SharedConfig) | 	c.flags.applyLogConfigOverrides(config.SharedConfig) | ||||||
| 	l, err := c.configureLogging(config) | 	l, err := c.configureLogging(config) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		c.UI.Error(err.Error()) | 		c.UI.Error(err.Error()) | ||||||
| @@ -672,6 +672,12 @@ func (c *ServerCommand) runRecoveryMode() int { | |||||||
|  |  | ||||||
| 	c.UI.Output("") | 	c.UI.Output("") | ||||||
|  |  | ||||||
|  | 	// Tests might not want to start a vault server and just want to verify | ||||||
|  | 	// the configuration. | ||||||
|  | 	if c.flagTestVerifyOnly { | ||||||
|  | 		return 0 | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	for _, ln := range lns { | 	for _, ln := range lns { | ||||||
| 		handler := vaulthttp.Handler.Handler(&vault.HandlerProperties{ | 		handler := vaulthttp.Handler.Handler(&vault.HandlerProperties{ | ||||||
| 			Core:                  core, | 			Core:                  core, | ||||||
|   | |||||||
| @@ -286,6 +286,13 @@ func TestServer(t *testing.T) { | |||||||
| 			0, | 			0, | ||||||
| 			[]string{"-test-verify-only"}, | 			[]string{"-test-verify-only"}, | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			"recovery_mode", | ||||||
|  | 			testBaseHCL(t, "") + inmemHCL, | ||||||
|  | 			"", | ||||||
|  | 			0, | ||||||
|  | 			[]string{"-test-verify-only", "-recovery"}, | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, tc := range cases { | 	for _, tc := range cases { | ||||||
| @@ -295,26 +302,21 @@ func TestServer(t *testing.T) { | |||||||
| 			t.Parallel() | 			t.Parallel() | ||||||
|  |  | ||||||
| 			ui, cmd := testServerCommand(t) | 			ui, cmd := testServerCommand(t) | ||||||
| 			f, err := ioutil.TempFile("", "") |  | ||||||
| 			if err != nil { | 			f, err := os.CreateTemp(t.TempDir(), "") | ||||||
| 				t.Fatalf("error creating temp dir: %v", err) | 			require.NoErrorf(t, err, "error creating temp dir: %v", err) | ||||||
| 			} |  | ||||||
| 			f.WriteString(tc.contents) | 			_, err = f.WriteString(tc.contents) | ||||||
| 			f.Close() | 			require.NoErrorf(t, err, "cannot write temp file contents") | ||||||
| 			defer os.Remove(f.Name()) |  | ||||||
|  | 			err = f.Close() | ||||||
|  | 			require.NoErrorf(t, err, "unable to close temp file") | ||||||
|  |  | ||||||
| 			args := append(tc.args, "-config", f.Name()) | 			args := append(tc.args, "-config", f.Name()) | ||||||
|  |  | ||||||
| 			code := cmd.Run(args) | 			code := cmd.Run(args) | ||||||
| 			output := ui.ErrorWriter.String() + ui.OutputWriter.String() | 			output := ui.ErrorWriter.String() + ui.OutputWriter.String() | ||||||
|  | 			require.Equal(t, tc.code, code, "expected %d to be %d: %s", code, tc.code, output) | ||||||
| 			if code != tc.code { | 			require.Contains(t, output, tc.exp, "expected %q to contain %q", output, tc.exp) | ||||||
| 				t.Errorf("expected %d to be %d: %s", code, tc.code, output) |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			if !strings.Contains(output, tc.exp) { |  | ||||||
| 				t.Fatalf("expected %q to contain %q", output, tc.exp) |  | ||||||
| 			} |  | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Peter Wilson
					Peter Wilson