Skip to content

Commit

Permalink
Merge pull request #99 from odaridavid/resolve-cleartext
Browse files Browse the repository at this point in the history
Resolve cleartext errors
  • Loading branch information
odaridavid authored Jun 9, 2020
2 parents e53ac71 + 6b4bce8 commit 19d07de
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 16 deletions.
12 changes: 10 additions & 2 deletions app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
"oauth_client": [
{
"client_id": "564324081859-pp0b62lk19reni5p538ckse2dr6dr3li.apps.googleusercontent.com",
"client_id": "564324081859-1mq6f3s6a23k45romp1uepctunruou5p.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.k0d4black.theforce",
"certificate_hash": "113cb837d7d15580c33a4d642ff301877a14b840"
"certificate_hash": "2ed02f3b703354a87ed8fdf61772ccf523a4e339"
}
},
{
Expand Down Expand Up @@ -51,6 +51,14 @@
}
},
"oauth_client": [
{
"client_id": "564324081859-0asij4ni6kmpr6cp9i798vmhipoqtrps.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.k0d4black.theforce.debug",
"certificate_hash": "113cb837d7d15580c33a4d642ff301877a14b840"
}
},
{
"client_id": "564324081859-4udbte4ljtq9upkgevouj8rf32albjbr.apps.googleusercontent.com",
"client_type": 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ internal class StarWarsRequestDispatcher : Dispatcher() {

override fun dispatch(request: RecordedRequest): MockResponse {
return when (request.path) {
"/people?search=$EXISTING_SEARCH_PARAMS" -> {
"/people/?search=$EXISTING_SEARCH_PARAMS" -> {
MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(searchSuccess)
}
"/people?search=$NON_EXISTENT_SEARCH_PARAMS" -> {
"/people/?search=$NON_EXISTENT_SEARCH_PARAMS" -> {
MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(searchNoMatch)
}
"/people?search=$ERROR_SEARCH_PARAMS" -> {
"/people/?search=$ERROR_SEARCH_PARAMS" -> {
MockResponse()
.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
.setBody(notFound)
Expand Down
2 changes: 1 addition & 1 deletion app/src/release/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-->
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">swapi.dev</domain>
</domain-config>
</network-security-config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
*
* Copyright 2020 David Odari
*
* Licensed 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
* http://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 com.k0d4black.theforce.data.remote


fun String.enforceHttps(): String =
if (!this.contains("https"))
this.replace("http", "https")
else this
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import retrofit2.http.Url

interface StarWarsApiService {

@GET("people")
@GET("people/")
suspend fun searchCharacters(@Query("search") params: String): SearchResponse

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.k0d4black.theforce.data.remote.repository

import com.k0d4black.theforce.data.remote.api.StarWarsApiService
import com.k0d4black.theforce.data.remote.enforceHttps
import com.k0d4black.theforce.data.remote.mappers.toDomain
import com.k0d4black.theforce.domain.models.Film
import com.k0d4black.theforce.domain.models.Planet
Expand All @@ -14,26 +15,26 @@ class CharacterDetailsRepository(
) : ICharacterDetailsRepository {

override suspend fun getCharacterPlanet(characterUrl: String): Flow<Planet> = flow {
val planetResponse = apiService.getPlanet(characterUrl)
val planet = apiService.getPlanetDetails(planetResponse.homeworldUrl)
val planetResponse = apiService.getPlanet(characterUrl.enforceHttps())
val planet = apiService.getPlanetDetails(planetResponse.homeworldUrl.enforceHttps())
emit(planet.toDomain())
}

override suspend fun getCharacterSpecies(characterUrl: String): Flow<List<Specie>> = flow {
val speciesResponse = apiService.getSpecies(characterUrl)
val speciesResponse = apiService.getSpecies(characterUrl.enforceHttps())
val species = mutableListOf<Specie>()
for (specieUrl in speciesResponse.specieUrls) {
val specie = apiService.getSpecieDetails(specieUrl)
val specie = apiService.getSpecieDetails(specieUrl.enforceHttps())
species.add(specie.toDomain())
}
emit(species)
}

override suspend fun getCharacterFilms(characterUrl: String): Flow<List<Film>> = flow {
val filmsResponse = apiService.getFilms(characterUrl)
val filmsResponse = apiService.getFilms(characterUrl.enforceHttps())
val films = mutableListOf<Film>()
for (filmUrl in filmsResponse.filmUrls) {
val film = apiService.getFilmDetails(filmUrl)
val film = apiService.getFilmDetails(filmUrl.enforceHttps())
films.add(film.toDomain())
}
emit(films)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ internal class StarWarsRequestDispatcher : Dispatcher() {

override fun dispatch(request: RecordedRequest): MockResponse {
return when (request.path) {
"/people?search=$EXISTING_SEARCH_PARAMS" -> {
"/people/?search=$EXISTING_SEARCH_PARAMS" -> {
MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(getJson("json/character_search.json"))
}
"/people?search=$NON_EXISTENT_SEARCH_PARAMS" -> {
"/people/?search=$NON_EXISTENT_SEARCH_PARAMS" -> {
MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
//App Versioning
versionCodeMajor = 2
versionCodeMinor = 1
versionCodePatch = 0
versionCodePatch = 1
versionName = "$versionCodeMajor.$versionCodeMinor.$versionCodePatch"

//Dependencies Version - Presentation
Expand Down

0 comments on commit 19d07de

Please sign in to comment.