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

Prüfung auf Vereinfachung: SecurityConfigurationTest #232

Open
MrSebastian opened this issue May 15, 2024 · 0 comments
Open

Prüfung auf Vereinfachung: SecurityConfigurationTest #232

MrSebastian opened this issue May 15, 2024 · 0 comments

Comments

@MrSebastian
Copy link
Member

Es sollte geprüft werden ob für die SecurityConfigurationTests eine Vereinfachung möglich ist.

Die Tests prüfen ob die Konfiguration der Authentifizierung er Endpunkte korrekt ist; wann darf man anonym zugreifen und wann muss man authentifiziert sein. Aktuell muss man jeweils 2 Testmethoden schreiben. Die Gedanke war ob man dass nicht mehr durch konfiguration abbilden könnte.

Die Methoden allerdings nicht so groß sind hat das Thema aus meiner Sicht keine große Relevanz.


Ein CodeSnipper eines Versuches
        static Stream<Arguments> getAuthenticatedTestArguments() {
            return Stream.of();
        }

        static Stream<Arguments> getAnonymousTestArguments() {
            return Stream.of(createArgumentsForUnauthorized("/businessActions/konfiguration/ABSCHLUSSTEXT"),
                    createPostArguments("/businessActions/konfiguration/ABSCHLUSSTEXT", status().isUnauthorized()),
                    createArgumentsForUnauthorized("/businessActions/konfiguration"),
                    createArgumentsForUnauthorized("/businessActions/kennbuchstaben"),
                    createGetArguments("/businessActions/konfigurationUnauthorized/WILLKOMMENSTEXT", status().isNoContent()));
        }

        private static Arguments createArgumentsForUnauthorized(final String path) {
            return createGetArguments(path, status().isUnauthorized());
        }

        private static Arguments createGetArguments(final String path, final ResultMatcher resultMatcher) {
            return createArguments(path, get(path), resultMatcher);
        }

        private static Arguments createPostArguments(final String path, final ResultMatcher resultMatcher) {
            return createArguments(path, post(path).with(csrf()).contentType(MediaType.APPLICATION_JSON), resultMatcher);
        }

        private static Arguments createArguments(final String name, final MockHttpServletRequestBuilder requestBuilder, final ResultMatcher resultMatcher) {
            return Arguments.of(name, requestBuilder, resultMatcher);
        }

Allerdings wird es um einiges komplizierter wenn man noch Stubbing definieren muss oder einen Button im Request benötigt. Daher würde ich daraus ein gesondertes Issue machen.

Originally posted by @MrSebastian in #231 (comment)

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

No branches or pull requests

1 participant