input: Write a python function to create a Flask app with basic authentication and protected and unprotected endpoints.
  assert app.test_client().get('/protected', headers={'Authorization': 'Basic dXNlcjpwYXNz'}).data == b'You have access!'
  assert app.test_client().get('/protected').status_code == 401
  assert app.test_client().get('/unprotected').data == b'This endpoint is unprotected!'
output: def create_flask_app():
      from flask import Flask, request, Response
      
      app = Flask(__name__)
      
      # Basic authentication check
      def check_auth(username, password):
          return username == 'user' and password == 'pass'
      
      # A helper function to authenticate
      def authenticate():
          return Response(
              'Could not verify your access level for that URL.\n'
              'You have to login with proper credentials', 401,
              {'WWW-Authenticate': 'Basic realm="Login Required"'})
      
      # Protected route
      @app.route('/protected')
      def protected():
          auth = request.authorization
          if not auth or not check_auth(auth.username, auth.password):
              return authenticate()
          return 'You have access!'
      
      # Unprotected route
      @app.route('/unprotected')
      def unprotected():
          return 'This endpoint is unprotected!'
      
      return app
  
  app = create_flask_app()