Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin config parsing code #3939

Merged
merged 5 commits into from
Mar 2, 2023
Merged

Conversation

azdagron
Copy link
Member

@azdagron azdagron commented Mar 2, 2023

Recent changes to the plugin config parsing to retain plugin order failed to account for the more verbose HCL or JSON forms.

This PR fixes the code to handle these forms as well as prevents duplicate declarations, which was accidentally allowed as part of the previous change.

Fixes: #3938

Recent changes to the plugin config parsing to retain plugin order
failed to account for the more verbose HCL or JSON forms.

This PR fixes the code to handle these forms as well as prevents
duplicate declarations, which was accidentally allowed as part of the
previous change.

Fixes: spiffe#3938

Signed-off-by: Andrew Harding <azdagron@gmail.com>

_, ok = configs.Find("WHATEVER", "NAME1")
require.False(t, ok)
t.Run("Plugin declared more than once", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @azdagron what do you think about having an extra test case for an invalid number of keys here?

	t.Run("Invalid number of keys", func(t *testing.T) {
		config := `
			plugins {
				KEY1 "KEY2" KEY3 {
					plugin_data = "DATA3"
					enabled = false
				}
			}
		`
		root := struct {
			Plugins ast.Node
		}{}
		err := hcl.Decode(&root, config)
		require.NoError(t, err)

		_, err = PluginConfigsFromHCLNode(root.Plugins)
		require.EqualError(t, err, "expected one or two keys on the plugin item but got 3")
	})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Added.

@guilhermocc
Copy link
Contributor

Thank you for this @azdagron

Signed-off-by: Andrew Harding <azdagron@gmail.com>
@evan2645 evan2645 added this to the 1.6.2 milestone Mar 2, 2023
@MarcosDY MarcosDY merged commit 3346e40 into spiffe:main Mar 2, 2023
@azdagron azdagron deleted the fix-plugin-parsing branch March 2, 2023 22:44
@amartinezfayo amartinezfayo modified the milestones: 1.6.2, 1.6.3 Apr 5, 2023
stevend-uber pushed a commit to stevend-uber/spire that referenced this pull request Oct 16, 2023
* Fix plugin config parsing code

Recent changes to the plugin config parsing to retain plugin order
failed to account for the more verbose HCL or JSON forms.

This PR fixes the code to handle these forms as well as prevents
duplicate declarations, which was accidentally allowed as part of the
previous change.

Fixes: spiffe#3938

Signed-off-by: Andrew Harding <azdagron@gmail.com>

* Add another test case

Signed-off-by: Andrew Harding <azdagron@gmail.com>

---------

Signed-off-by: Andrew Harding <azdagron@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1.6 broken json config
5 participants