@Override
    public void scrubRegistrationProperties() {
        if (!exist()) {
            return;
        }
        try {
            PropertiesConfiguration config = new PropertiesConfiguration();
            config.setIOFactory(new FilteringOutputWriterFactory());
            PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout();
            layout.setLineSeparator("\n");
            layout.load(config, reader());
            try (FileWriter out = new FileWriter(this.configFile)) {
                layout.save(config, out);
            }
            loadProperties();
        } catch (ConfigurationException | IOException e) {
            LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
        }
    }
@Test
    void shouldScrubTheAutoRegistrationProperties() throws Exception {
        String originalContents = """
                #
                # file autogenerated by chef, any changes will be lost
                #
                # the registration key
                agent.auto.register.key = some secret key

                # the resources on this agent
                agent.auto.register.resources = some,resources

                # The hostname of this agent
                agent.auto.register.hostname = agent42.example.com

                # The environments this agent belongs to
                agent.auto.register.environments = production,blue

                """;
        FileUtils.writeStringToFile(configFile, originalContents, UTF_8);

        AgentAutoRegistrationProperties properties = new AgentAutoRegistrationPropertiesImpl(configFile);
        properties.scrubRegistrationProperties();

        String newContents = """
                #
                # file autogenerated by chef, any changes will be lost
                #
                # the registration key
                # The autoregister key has been intentionally removed by Go as a security measure.
                # agent.auto.register.key = some secret key

                # the resources on this agent
                # This property has been removed by Go after attempting to auto-register with the Go server.
                # agent.auto.register.resources = some,resources

                # The hostname of this agent
                # This property has been removed by Go after attempting to auto-register with the Go server.
                # agent.auto.register.hostname = agent42.example.com

                # The environments this agent belongs to
                # This property has been removed by Go after attempting to auto-register with the Go server.
                # agent.auto.register.environments = production,blue

                """;
        assertThat(FileUtils.readFileToString(configFile, UTF_8)).isEqualTo(newContents);
    }