Copilot commented on code in PR #16523: URL: https://github.com/apache/grails-core/pull/16523#discussion_r4185445039
########## grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/InsertableUpdatableMappingSpec.groovy: ########## @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.orm.hibernate.cfg.domainbinding + +import grails.gorm.annotation.Entity +import grails.gorm.tests.HibernateGormDatastoreSpec + +/** + * Proves, through the GORM API, that {@code insertable: false} and {@code updatable: false} in the mapping keep the + * column out of the INSERT and the UPDATE statements. The database is read with a native query because the in-memory + * entity still holds the value the application assigned. + */ +class InsertableUpdatableMappingSpec extends HibernateGormDatastoreSpec { + + void setupSpec() { + manager.registerDomainClasses(IUMColumns) + } + + private String column(Long id, String name) { + sessionFactory.currentSession + .createNativeQuery("select ${name} from ium_columns where id = :id".toString(), String) + .setParameter('id', id) + .uniqueResult() + } Review Comment: This helper uses `sessionFactory.currentSession` while the tests elsewhere use `session` (e.g., `session.clear()`). For consistency and to avoid any mismatch if the backing session changes, consider using the same `session` instance throughout (e.g., `session.createNativeQuery(...)`) or passing the session explicitly into the helper. ########## grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/InsertableUpdatableMappingSpec.groovy: ########## @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.orm.hibernate.cfg.domainbinding + +import grails.gorm.annotation.Entity +import grails.gorm.tests.HibernateGormDatastoreSpec + +/** + * Proves, through the GORM API, that {@code insertable: false} and {@code updatable: false} in the mapping keep the + * column out of the INSERT and the UPDATE statements. The database is read with a native query because the in-memory + * entity still holds the value the application assigned. + */ +class InsertableUpdatableMappingSpec extends HibernateGormDatastoreSpec { + + void setupSpec() { + manager.registerDomainClasses(IUMColumns) + } + + private String column(Long id, String name) { + sessionFactory.currentSession + .createNativeQuery("select ${name} from ium_columns where id = :id".toString(), String) + .setParameter('id', id) + .uniqueResult() + } Review Comment: The column name is interpolated directly into the SQL string, which is susceptible to SQL injection if `name` ever becomes non-constant (even in tests, it’s a sharp edge and easy to copy/paste into production code). Since identifiers can’t be bound as parameters, consider whitelisting `name` (e.g., switch/Map of allowed logical names to literal column identifiers) and interpolating only the vetted identifier. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
