API 1.2.2 fix firebase string, customer login

This commit is contained in:
Tibor Bossanyi
2023-04-11 16:53:33 +02:00
parent bdbfe1cd48
commit 73d189a357
13 changed files with 49 additions and 14 deletions
@@ -155,7 +155,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
}
@PostMapping("/club_registration")
fun clubRegistration(@Valid @RequestBody json: String, @Value("\${firebase.key}") apiKey: String): ResponseEntity<*> {
fun clubRegistration(@Valid @RequestBody json: String, @Value("\${firebase.key}") apiKey: java.lang.String): ResponseEntity<*> {
val newUser: ClubUser = ClubUser().fromJson(json)
@@ -25,7 +25,7 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
var serviceBeans: ServiceBeans? = null
@PostMapping("/diet_registration")
fun insert(@RequestBody dietCustomerJson: String, @Value("\${firebase.key}") apiKey: String): ResponseEntity<*> {
fun insert(@RequestBody dietCustomerJson: String, @Value("\${firebase.key}") apiKey: java.lang.String): ResponseEntity<*> {
val newDietCustomer: DietCustomer = DietCustomer().fromJson(dietCustomerJson)
if ( newDietCustomer.email.isEmpty()) {
@@ -61,7 +61,7 @@ class JwtSecurityConfig {
return object : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**")
.allowedOriginPatterns("https://*.diet4you.eu", "https://*.diet4you.hu", "https://*.workouttest.org", "http://localhost:[*]")
.allowedOriginPatterns("https://diet4you.hu", "https://diet4you.eu", "https://*.diet4you.eu", "https://*.diet4you.hu", "https://*.workouttest.org", "http://localhost:[*]")
//.allowedOrigins("*")
.allowedMethods("POST", "GET", "OPTIONS", "HEAD")
.maxAge(3600)
@@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets
import java.util.*
@Service
class Firebase(@Value("\${firebase.key}") private val apiKey: String) {
class Firebase(@Value("\${firebase.key}") private val apiKey: java.lang.String) {
private val firebaseBaseUrl: String = "https://identitytoolkit.googleapis.com/v1/accounts"
var statusCode: Int = 0
var error: String = ""
@@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs
# if the database structure has been changed, increment this version number
application.version=1.2.1
application.version=1.2.2
jwt.secret=aitrainer
@@ -14,11 +14,11 @@ logging.config=classpath:logback-spring.xml
logging.file=logs
# if the database structue has been changed, increment this version number
application.version=1.2.1
application.version=1.2.2
jwt.secret=aitrainer
firebase.key=AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4
firebase.key=AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E
openai.key=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
spring.mail.properties.mail.mime.charset=UTF-8
@@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs
# if the database structue has been changed, increment this version number
application.version=1.2.1
application.version=1.2.2
jwt.secret=aitrainer
+1 -1
View File
@@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs
# if the database structure has been changed, increment this version number
application.version=1.2.1
application.version=1.2.2
jwt.secret=aitrainer
@@ -246,7 +246,7 @@ class CustomerTests {
}
@Test
fun testClubRegistration(@Value("\${firebase.key}") apiKey: String) {
fun testClubRegistration(@Value("\${firebase.key}") apiKey: java.lang.String) {
val json = "{\"firstname\":\"Tib\", \"email\": \"mr@andio.biz\", \"goal\": \"shape\", \"fitnessLevel\": \"advanced\", \"weight\": 85}"
val controller = CustomerController(customerRepository)
val response: ResponseEntity<*> = controller.clubRegistration(json, apiKey)
@@ -329,7 +329,7 @@ class CustomerTests {
}
@Test
fun `insert recipes successfully`() {
fun `get customer successfully`() {
authToken = Tokenizer.getToken()
val customer = Customer(
@@ -355,7 +355,37 @@ class CustomerTests {
val customerId = JSONObject(mvcResult.response.contentAsString).getInt("customerId")
println("MockCustomer Id $customerId")
assertTrue(customerId > 0)
customerRepository.delete(customer)
}
@Test
fun `login successfully`() {
authToken = Tokenizer.getToken()
val user = User(
username = "sw2@andio.biz",
password = "andio2009",
firebaseUid = "",
)
val mvcResult: MvcResult = mockMvc.perform(
MockMvcRequestBuilders.post("/api/login")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer $authToken")
.content(toJson(user))
)
.andExpect(MockMvcResultMatchers.status().isOk)
.andExpect(MockMvcResultMatchers.jsonPath("$.name").value("Bos"))
.andExpect(MockMvcResultMatchers.jsonPath("$.firstname").value("Kakadu"))
.andExpect(MockMvcResultMatchers.jsonPath("$.birthYear").value(1972))
.andReturn()
val customerId = JSONObject(mvcResult.response.contentAsString).getInt("customerId")
println("MockCustomer Id $customerId")
assertEquals(customerId, 103)
}
private fun toJson(obj: Any): String {
return Gson().toJson(obj)
}
@@ -21,7 +21,7 @@ class FirebaseTest {
}
@Test
fun testAuth(@Value("\${firebase.key}") apiKey: String) {
fun testAuth(@Value("\${firebase.key}") apiKey: java.lang.String) {
this.firebase = Firebase(apiKey)
val email = "user@exemple.com"
val password = "verystrictpassword1"